




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)
文檔簡介
1、移動聯(lián)通電信獲取基站數(shù)據(jù)庫的方案在googleAPI里提供了基站信息的獲取類TelephonyManager,通過其方法getCellLocation得到CellLocation即可獲取到基站相關(guān)信息但CellLocation是個抽象類,所以在具體使用時需要判斷接入的網(wǎng)絡(luò)制式來用其子類CdmaCellLocation或GsmCellLocation 來強轉(zhuǎn)CdmaCellLocation對應(yīng)CDMA網(wǎng),GsmCellLocation對應(yīng)GSM網(wǎng)三大網(wǎng)絡(luò)運營商的網(wǎng)絡(luò)制式對應(yīng)如下:移動2G 網(wǎng) -> GSM移動3G 網(wǎng) -> TD-SCDMA電信2G 網(wǎng) -> CDMA
2、電信3G 網(wǎng) -> CDMA2000聯(lián)通2G 網(wǎng) -> GSM聯(lián)通3G 網(wǎng) -> WCDMA由此可見移動,聯(lián)通2G 網(wǎng)都可使用GsmCellLocation電信2G,3G網(wǎng)則使用CdmaCellLocation那么移動3G和聯(lián)通3G又當(dāng)如何其實經(jīng)本人親測,移動3G網(wǎng)也可使用GsmCellLocation,聽說是TD-SCDMA衍生于GSM,具體原因咱也不用糾結(jié)了,反正能用就是了而聯(lián)通的WCDMA據(jù)說也可使用GsmCellLocation,那姑且就是這樣吧,有條件的童鞋試一試吧。對于網(wǎng)絡(luò)制式的判斷調(diào)用TelephonyManager.getNetworkType()可有多種情況
3、,如下:· NETWORK_TYPE_UNKNOWN· NETWORK_TYPE_GPRS· NETWORK_TYPE_EDGE· NETWORK_TYPE_UMTS· NETWORK_TYPE_HSDPA· NETWORK_TYPE_HSUPA· NETWORK_TYPE_HSPA· NETWORK_TYPE_CDMA· NETWORK_TYPE_EVDO_0· NETWORK_TYPE_EVDO_A· NETWORK_TYPE_EVDO_B· NETWORK_TYPE_1
4、xRTT· NETWORK_TYPE_IDEN· NETWORK_TYPE_LTE· NETWORK_TYPE_EHRPD通過對網(wǎng)絡(luò)類型判斷后獲取對應(yīng)基站信息代碼片段如下:Html代碼 1. public static ArrayList<CellIDInfo> getCellIDInfo(Context context) throws Exception 2.
5、160; 3. TelephonyManager manager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); 4. 5. &
6、#160;ArrayList<CellIDInfo> CellID = new ArrayList<CellIDInfo>(); 6. CellIDInfo currentCell = new CellIDInfo(); 7. 8. i
7、nt type = manager.getNetworkType(); 9. Log.d(TAG, "getCellIDInfo-> NetworkType = " + type); 10.
8、0; int phoneType = manager.getPhoneType(); 11. Log.d(TAG, "getCellIDInfo-> phoneType = " + phoneType); 12.
9、 13. if (type = WORK_TYPE_GPRS / GSM網(wǎng) 14. &
10、#160; | type = WORK_TYPE_EDGE 15. | type = WORK_TYPE_HSDPA) 16.
11、; 17. GsmCellLocation gsm = (GsmCellLocation) manager.getCellLocation(); 18. if (gsm =
12、null) 19. 20. Log.e(TAG, "GsmCellLocation is null!"); 21.
13、60; return null; 22. 23.
14、160; 24. 25. int lac = gsm.getLac(); 26. String mcc = manager.getNetworkOperator().substring(0,
15、60;3); 27. String mnc = manager.getNetworkOperator().substring(3, 5); 28. int cid = gsm.getCid();
16、160; 29. 30. currentCell.cellId = gsm.getCid(); 31.
17、 currentCell.mobileCountryCode = mcc; 32. currentCell.mobileNetworkCode = mnc; 33. currentCell.locationAreaCo
18、de = lac; 34. 35. currentCell.radioType = "gsm" 36.
19、0; 37. CellID.add(currentCell); 38. 39.
20、0; / 獲得鄰近基站信息 40. List<NeighboringCellInfo> list = manager.getNeighboringCellInfo(); 41. in
21、t size = list.size(); 42. for (int i = 0; i < size; i+) 43. 44.
22、 CellIDInfo info = new CellIDInfo(); 45. info.cellId = list.get(i).getCid(); 46.
23、 info.mobileCountryCode = mcc; 47. info.mobileNetworkCode = mnc; 48.
24、0; info.locationAreaCode = lac; 49. 50. CellID
25、.add(info); 51. 52. 53. else if (type = WORK_TYPE_CDM
26、A / 電信cdma網(wǎng) 54. | type = WORK_TYPE_1xRTT 55.
27、0; | type = WORK_TYPE_EVDO_0 56. | type = WORK_TYPE_EVDO_A) 57. 58. &
28、#160; 59. CdmaCellLocation cdma = (CdmaCellLocation) manager.getCellLocation(); 60.
29、 if (cdma = null) 61. 62. Log.e(TAG,
30、;"CdmaCellLocation is null!"); 63. return null; 64. 65.
31、; 66. int lac = cdma.getNetworkId(); 67. String mcc =
32、160;manager.getNetworkOperator().substring(0, 3); 68. String mnc = String.valueOf(cdma.getSystemId(); 69. int
33、;cid = cdma.getBaseStationId(); 70. 71. currentCell.cellId = cid; 72.
34、160; currentCell.mobileCountryCode = mcc; 73. currentCell.mobileNetworkCode = mnc; 74.
35、0; currentCell.locationAreaCode = lac; 75. 76. currentCell.radioType = "cdma" 77.
36、; 78. CellID.add(currentCell); 79. 80.
37、; / 獲得鄰近基站信息 81. List<NeighboringCellInfo> list = manager.getNeighboringCellInfo(); 82. int size
38、160;= list.size(); 83. for (int i = 0; i < size; i+) 84. 85. &
39、#160; CellIDInfo info = new CellIDInfo(); 86. info.cellId = list.get(i).getCid(); 87. &
40、#160; info.mobileCountryCode = mcc; 88. info.mobileNetworkCode = mnc; 89.
41、; info.locationAreaCode = lac; 90. 91. CellID.add(info);
42、160; 92. 93. 94. 95. return CellID;
43、60; 96. 97. 從GOOGLE的API文檔里總共有14鐘網(wǎng)絡(luò)類型,這里只羅列了其中7種,其他的主要是本人也不太清楚其對應(yīng)到的網(wǎng)絡(luò)制式是怎樣的所以部分童鞋的SIM卡網(wǎng)絡(luò)制式不在這7種之內(nèi),自己根據(jù)實際情況看看它是歸類于GSM還是CDMA在添進去就可以了網(wǎng)絡(luò)上多數(shù)教程是講GSM網(wǎng)獲取基站的,而忽略了C網(wǎng)的基站這里我們可以比較一下GSM 和 CD
44、MA 在獲取基站信息時的不同之處GSM:int lac = gsm.getLac();String mcc = manager.getNetworkOperator().substring(0, 3);String mnc = manager.getNetworkOperator().substring(3, 5);int cid = gsm.getCid();CDMA:int lac = cdma.getNetworkId();String mcc = manager.getNetworkOperator().substring(0, 3);String mnc = String.value
45、Of(cdma.getSystemId();int cid = cdma.getBaseStationId();在獲取區(qū)域碼LAC時GSM使用的是GsmCellLocation.getLac(),CDMA則用CdmaCellLocation.getNetworkId()來代替在獲取基站ID時GSM使用的是GsmCellLocation.getCid(),CDMA則用CdmaCellLocation.getBaseStationId()來代替前面獲取到的都是單個基站的信息,后面再獲取周圍鄰近基站信息以輔助通過基站定位的精準性TelephonyManager.getNeighboringCellI
46、nfo(),將其也放入基站信息LIST表中最后通過google提供的gear接口獲取經(jīng)緯度,代碼如下:Html代碼 1. public static Location callGear(List<CellIDInfo> cellID) 2. if (cellID = null | cellID.size()&
47、#160;= 0) 3. return null; 4. 5.
48、160; DefaultHttpClient client = new DefaultHttpClient(); 6. HttpPost post = new HttpPost("");
49、60;7. JSONObject holder = new JSONObject(); 8. 9. try
50、 10. holder.put("version", "1.1.0"); 11.
51、160; holder.put("host", ""); 12. holder.put("home_
52、mobile_country_code", cellID.get(0).mobileCountryCode); 13. holder.put("home_mobile_network_code", cellID.get(0).mobileN
53、etworkCode); 14. holder.put("radio_type", cellID.get(0).radioType); 15.
54、; holder.put("request_address", true); 16.
55、0; if ("460".equals(cellID.get(0).mobileCountryCode) 17. holder.put(&qu
56、ot;address_language", "zh_CN"); 18. else 19.
57、60; holder.put("address_language", "en_US"); 20.
58、 21. JSONObject data,current_data; 22. 23.
59、160; JSONArray array = new JSONArray(); 24.
60、0; 25. current_data = new JSONObject(); 26.
61、60; current_data.put("cell_id", cellID.get(0).cellId); 27.
62、 current_data.put("location_area_code", cellID.get(0).locationAreaCode); 28. current_data.put("mobile_
63、country_code", cellID.get(0).mobileCountryCode); 29. current_data.put("mobile_network_code", cellID.get(0).mobileNetwork
64、Code); 30. current_data.put("age", 0); 31.
65、0; current_data.put("signal_strength", -60); 32. current_data.put
66、("timing_advance", 5555); 33. array.put(current_data); 34.
67、 35. if (cellID.size() > 2)
68、0;36. for (int i = 1; i < cellID.size(); i+) 37.
69、; data = new JSONObject(); 38.
70、0; data.put("cell_id", cellID.get(i).cellId); 39.
71、60; data.put("location_area_code", cellID.get(i).locationAreaCode); 40. data.
72、put("mobile_country_code", cellID.get(i).mobileCountryCode); 41. data.put("mobile_network_code&
73、quot;, cellID.get(i).mobileNetworkCode); 42. data.put("age", 0); 43.
74、60; array.put(data); 44. &
75、#160; 45. 46. 47. &
76、#160; 48. 49.
77、; 50. holder.
78、put("cell_towers", array); 51.
79、60; 52. StringEntity se = new StringEntity(holder.toString(); 53.
80、 Log.e("Location send", holder.toString(); 54. &
81、#160; post.setEntity(se); 55. HttpResponse resp = client.execute(post);
82、 56. 57. HttpEntity entity = resp.getEntity(); 58. 59.
83、0; BufferedReader br = new BufferedReader( 60. &
84、#160; new InputStreamReader(entity.getContent(); 61.
85、0; StringBuffer sb = new StringBuffer(); 62. String result = br.readLine(); 63.
86、160; while (result != null) 64.
87、60; Log.e("Locaiton reseive->", result); 65.
88、 sb.append(result); 66. result =&
89、#160;br.readLine(); 67. 68.
90、60; 69. data = new JSONObject(sb.toString(); 70.
91、0; 71. data = (JSONObject) data.ge
92、t("location"); 72. 73. Location loc = new LocatioWORK_PROVIDER); 74.
93、; loc.setLatitude(Double) data.get("latitude"); 75. &
94、#160; loc.setLongitude(Double) data.get("longitude"); 76. loc.setAccuracy(Float.parseFloat(data
95、.get("accuracy").toString(); 77. loc.setTime( System.currentTimeMillis();/AppUtil.getUTCTime(); 78. &
96、#160; return loc; 79. catch (JSONException e)
97、160; 80. e.printStackTrace(); 81.
98、0; return null; 82. catch (UnsupportedEncodingException e) 83.
99、60; e.printStackTrace(); 84. catch (ClientProtocolException e) 85.
100、0; e.printStackTrace(); 86. catch (IOException
101、;e) 87. e.printStackTrace(); 88.
102、; 89. 90. return null; 91. 大家注意看這行holder.put("radio_type", cellID.get(0).radioType);GSM就用"
103、gsm",CDMA就用"cdma"這個千萬別搞混了,不然就獲取不到信息了值得一提的是C網(wǎng)獲取基站再定位那偏差不是一般的大,是恨大,將近1千米了,大概是C網(wǎng)基站較少的緣故吧最后通過經(jīng)緯度獲取地理位置信息,代碼如下:Java代碼 1. public static String getAddress(Location itude) throws Exception 2. &
104、#160;String resultString = "" 3. 4. /* 這里采用get方法,直接將參數(shù)加到URL上 */ 5. String urlString = String.format("",&
105、#160;itude.getLatitude(), itude.getLongitude(); 6. Log.i("URL", urlString); 7. 8. /* 新建HttpClient */ 9. &
106、#160; HttpClient client = new DefaultHttpClient(); 10. /* 采用GET方法 */ 11. HttpGet get = new HttpGet(urlString)
107、; 12. try 13. /* 發(fā)起GET請求并獲得返回數(shù)據(jù) */ 14. HttpResponse response = client.execute(get); 15. HttpEntity entity = response.getEntity(); 16.
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 行政處罰結(jié)果信息公開二零二五年
- 相關(guān)材料2025年計算機二級考試試題及答案
- 的停車場承包合同范文
- 國際訪問教授聘用協(xié)議
- 二零二五自駕游拼車協(xié)議
- 停車收費協(xié)議書
- 荊州市古城區(qū)景觀帶大氣污染物分布的季節(jié)特征與消減效應(yīng)的研究
- 多模式多端口低剖面寬帶天線技術(shù)
- HPM視角下的數(shù)列教學(xué)研究
- 苔草屬植物胡蘿卜狀根對難溶性磷源響應(yīng)及地上生物量調(diào)控機制研究
- 山東省青島市市南區(qū)育才中學(xué)2025年中考數(shù)學(xué)一模試卷(含答案)
- 第十個全民國家安全教育日“全民國家安全教育 走深走實十周年”心得體會
- 網(wǎng)絡(luò)運維方案
- 江蘇省常熟市2022-2023學(xué)年高一下學(xué)期期中考試歷史試題 含答案
- 2025年04月國家廣播電視總局直屬事業(yè)單位公開招聘310人筆試歷年典型考題(歷年真題考點)解題思路附帶答案詳解
- 地鐵施工監(jiān)測監(jiān)理細則
- 呼吸機的使用操作流程
- “雙碳”目標(biāo)下數(shù)智化供應(yīng)鏈運作管理策略研究
- 住建局安全管理匯報
- 粉體輸送設(shè)備安裝工程施工合同
- 空調(diào)定期清洗消毒制度消毒
評論
0/150
提交評論