GSM基站定位信息解析为经纬度方法

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

01. ///


02./// 将基站定位信息转化为 经纬度信息
03.///

04./// 移动用户所属国家代号:中国为460
05./// 移动网号码,中国联通CDMA系统的MNC为03,中国移动的为00。
06./// 代表一个移动基站
07./// 地区区域码
08./// 纬度
09./// 经度
10.public static void GoogleLoc(string mcc, string mnc, uint cellid, uint lac, out double Lat, out double Lng)
11.{
12.
13. string json = "";
14. json += "{";
15. json += "\"version\":\"1.1.0\"" + ",";
16. json += "\"host\":\"\"" + ",";
17. json += "\"request_address\": \"false\"" + ",";
18. json += "\"address_language\": \"zh_CN\"" + ",";
19. json += "\"radio_type\":\"gsm\"" + ",";
20. json += "\"cell_towers\":[";
21.
22. json += "{";
23. json += "\"cell_id\":" + cellid + ",";
24. json += "\"location_area_code\":" + lac + ",";
25. json += "\"mobile_country_code\":" + mcc + ",";
26. json += "\"mobile_network_code\":" + mnc;
27. json += "}";
28.
29. json += "]}";
30.
31. string requestJson = json;
32. string responseJson = string.Empty;
33. try
34. {
35. ServicePointManager.Expect100Continue = false;
36. System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
37. byte[] data = encoding.GetBytes(requestJson);
38.
39. HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(@"/loc/json");
40. myRequest.Timeout = 16000;
41.
42. myRequest.Method = "POST";
43. myRequest.ContentType = "application/requestJson";
44. myRequest.ContentLength = data.Length;
45. Stream newStream = myRequest.GetRequestStream();
46.
47. newStream.Write(data, 0, data.Length);
48. newStream.Close();
49.
50. HttpWebResponse myResponse = (HttpWebResponse)myRequest.GetResponse();
51.
52. StreamReader reader = new StreamReader(myResponse.GetResponseStream(), System.Text.Encoding.Default);
53. responseJson = reader.ReadToEnd();
54. if (responseJson != "{}")
55. {
56. try
57. {
58. int index1 = responseJson.IndexOf("latitude");
59. int index2 = responseJson.IndexOf(":", index1);
60. int index3 = responseJson.IndexOf(",", index2);
61. Lat = Convert.ToDouble(responseJson.Substring(index2 + 1, index3 - index2 - 1));
62.
63. index1 = responseJson.IndexOf("longitude");
64. index2 = responseJson.IndexOf(":", index1);
65. index3 = responseJson.IndexOf(",", index2);
66. Lng = Con

vert.ToDouble(responseJson.Substring(index2 + 1, index3 - index2 - 1));
67.
68. }
69. catch (Exception)
70. {
71. throw new FormatException("解析google返回的json出错,返回内容为:" + responseJson);
72. }
73. }
74. else
75. {
76. Lat = 0;
77. Lng = 0;
78.
79. //ExceptionLogWriter.Write("没有此基站的位置信息,提交内容为:" + json);
80. }
81. }
82. catch (Exception ex)
83. {
84. throw new IOException("向Google获取基站位置信息失败。提交内容为:" + json, ex);
85. }
86.
87.}

相关文档
最新文档