移动联通电信获取基站数据库的方案.doc_第1页
移动联通电信获取基站数据库的方案.doc_第2页
移动联通电信获取基站数据库的方案.doc_第3页
移动联通电信获取基站数据库的方案.doc_第4页
移动联通电信获取基站数据库的方案.doc_第5页
已阅读5页,还剩7页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

移动联通电信获取基站数据库的方案在googleAPI里提供了基站信息的获取类TelephonyManager,通过其方法getCellLocation得到CellLocation即可获取到基站相关信息但CellLocation是个抽象类,所以在具体使用时需要判断接入的网络制式来用其子类CdmaCellLocation或GsmCellLocation来强转CdmaCellLocation对应CDMA网,GsmCellLocation对应GSM网三大网络运营商的网络制式对应如下:移动2G 网 - GSM移动3G 网 - TD-SCDMA电信2G 网 - CDMA电信3G 网 - CDMA2000联通2G 网 - GSM联通3G 网 - WCDMA由此可见移动,联通2G 网都可使用GsmCellLocation电信2G,3G网则使用CdmaCellLocation那么移动3G和联通3G又当如何其实经本人亲测,移动3G网也可使用GsmCellLocation,听说是TD-SCDMA衍生于GSM,具体原因咱也不用纠结了,反正能用就是了而联通的WCDMA据说也可使用GsmCellLocation,那姑且就是这样吧,有条件的童鞋试一试吧。对于网络制式的判断调用TelephonyManager.getNetworkType()可有多种情况,如下: 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_1xRTT NETWORK_TYPE_IDEN NETWORK_TYPE_LTE NETWORK_TYPE_EHRPD通过对网络类型判断后获取对应基站信息代码片段如下:Html代码1. publicstaticArrayListgetCellIDInfo(Contextcontext)throwsException2. 3. TelephonyManagermanager=(TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);4. 5. ArrayListCellID=newArrayList();6. CellIDInfocurrentCell=newCellIDInfo();7. 8. inttype=manager.getNetworkType();9. Log.d(TAG,getCellIDInfo-NetworkType=+type);10. intphoneType=manager.getPhoneType();11. Log.d(TAG,getCellIDInfo-phoneType=+phoneType);12. 13. if(type=TelephonyManager.NETWORK_TYPE_GPRS/GSM网14. |type=TelephonyManager.NETWORK_TYPE_EDGE15. |type=TelephonyManager.NETWORK_TYPE_HSDPA)16. 17. GsmCellLocationgsm=(GsmCellLocation)manager.getCellLocation();18. if(gsm=null)19. 20. Log.e(TAG,GsmCellLocationisnull!);21. returnnull;22. 23. 24. 25. intlac=gsm.getLac();26. Stringmcc=manager.getNetworkOperator().substring(0,3);27. Stringmnc=manager.getNetworkOperator().substring(3,5);28. intcid=gsm.getCid();29. 30. currentCell.cellId=gsm.getCid();31. currentCell.mobileCountryCode=mcc;32. currentCell.mobileNetworkCode=mnc;33. currentCell.locationAreaCode=lac;34. 35. currentCell.radioType=gsm;36. 37. CellID.add(currentCell);38. 39. /获得邻近基站信息40. Listlist=manager.getNeighboringCellInfo();41. intsize=list.size();42. for(inti=0;isize;i+)43. 44. CellIDInfoinfo=newCellIDInfo();45. info.cellId=list.get(i).getCid();46. info.mobileCountryCode=mcc;47. info.mobileNetworkCode=mnc;48. info.locationAreaCode=lac;49. 50. CellID.add(info);51. 52. 53. elseif(type=TelephonyManager.NETWORK_TYPE_CDMA/电信cdma网54. |type=TelephonyManager.NETWORK_TYPE_1xRTT55. |type=TelephonyManager.NETWORK_TYPE_EVDO_056. |type=TelephonyManager.NETWORK_TYPE_EVDO_A)57. 58. 59. CdmaCellLocationcdma=(CdmaCellLocation)manager.getCellLocation();60. if(cdma=null)61. 62. Log.e(TAG,CdmaCellLocationisnull!);63. returnnull;64. 65. 66. intlac=cdma.getNetworkId();67. Stringmcc=manager.getNetworkOperator().substring(0,3);68. Stringmnc=String.valueOf(cdma.getSystemId();69. intcid=cdma.getBaseStationId();70. 71. currentCell.cellId=cid;72. currentCell.mobileCountryCode=mcc;73. currentCell.mobileNetworkCode=mnc;74. currentCell.locationAreaCode=lac;75. 76. currentCell.radioType=cdma;77. 78. CellID.add(currentCell);79. 80. /获得邻近基站信息81. Listlist=manager.getNeighboringCellInfo();82. intsize=list.size();83. for(inti=0;isize;i+)84. 85. CellIDInfoinfo=newCellIDInfo();86. info.cellId=list.get(i).getCid();87. info.mobileCountryCode=mcc;88. info.mobileNetworkCode=mnc;89. info.locationAreaCode=lac;90. 91. CellID.add(info);92. 93. 94. 95. returnCellID;96. 97. 从GOOGLE的API文档里总共有14钟网络类型,这里只罗列了其中7种,其他的主要是本人也不太清楚其对应到的网络制式是怎样的所以部分童鞋的SIM卡网络制式不在这7种之内,自己根据实际情况看看它是归类于GSM还是CDMA在添进去就可以了网络上多数教程是讲GSM网获取基站的,而忽略了C网的基站这里我们可以比较一下GSM 和 CDMA 在获取基站信息时的不同之处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.valueOf(cdma.getSystemId();int cid = cdma.getBaseStationId();在获取区域码LAC时GSM使用的是GsmCellLocation.getLac(),CDMA则用CdmaCellLocation.getNetworkId()来代替在获取基站ID时GSM使用的是GsmCellLocation.getCid(),CDMA则用CdmaCellLocation.getBaseStationId()来代替前面获取到的都是单个基站的信息,后面再获取周围邻近基站信息以辅助通过基站定位的精准性TelephonyManager.getNeighboringCellInfo(),将其也放入基站信息LIST表中最后通过google提供的gear接口获取经纬度,代码如下:Html代码1. publicstaticLocationcallGear(ListcellID)2. if(cellID=null|cellID.size()=0)3. returnnull;4. 5. DefaultHttpClientclient=newDefaultHttpClient();6. HttpPostpost=newHttpPost(/loc/json);7. JSONObjectholder=newJSONObject();8. 9. try10. holder.put(version,1.1.0);11. holder.put(host,);12. holder.put(home_mobile_country_code,cellID.get(0).mobileCountryCode);13. holder.put(home_mobile_network_code,cellID.get(0).mobileNetworkCode);14. holder.put(radio_type,cellID.get(0).radioType);15. holder.put(request_address,true);16. if(460.equals(cellID.get(0).mobileCountryCode)17. holder.put(address_language,zh_CN);18. else19. holder.put(address_language,en_US);20. 21. JSONObjectdata,current_data;22. 23. JSONArrayarray=newJSONArray();24. 25. current_data=newJSONObject();26. current_data.put(cell_id,cellID.get(0).cellId);27. current_data.put(location_area_code,cellID.get(0).locationAreaCode);28. current_data.put(mobile_country_code,cellID.get(0).mobileCountryCode);29. current_data.put(mobile_network_code,cellID.get(0).mobileNetworkCode);30. current_data.put(age,0);31. current_data.put(signal_strength,-60);32. current_data.put(timing_advance,5555);33. array.put(current_data);34. 35. if(cellID.size()2)36. for(inti=1;i,result);65. sb.append(result);66. result=br.readLine();67. 68. 69. data=newJSONObject(sb.toString();70. 71. data=(JSONObject)data.get(location);72. 73. Locationloc=newLocation(LocationManager.NETWORK_PROVIDER);74. loc.setLatitude(Double)data.get(latitude);75. loc.setLongitude(Double)data.get(longitude);76. loc.setAccuracy(Float.parseFloat(data.get(accuracy).toString();77. loc.setTime(System.currentTimeMillis();/AppUtil.getUTCTime();78. returnloc;79. catch(JSONExceptione)80. e.printStackTrace();81. returnnull;82. catch(UnsupportedEncodingExceptione)83. e.printStackTrace();84. catch(ClientProtocolExceptione)85. e.printStackTrace();86. catch(IOExceptione)87. e.printStackTrace();88. 89. 90. returnnull;91. 大家注意看这行holder.put(radio_type, cellID.get(0).radioType);GSM就用gsm,CDMA就用cdma这个千万别搞混了,不然就获取不到信息了值得一提的是C网获取基站再定位那偏差不是一般的大,是恨大,将近1千米了,大概是C网基站较少的缘故吧最后通过经纬度获取地理位置信息,代码如下:Java代码1. publicstaticStringgetAddress(Locationitude)throwsException2. StringresultString=;3. 4. /*这里采用get方法,直接将参数加到URL上*/5. StringurlString=String.format(/maps/geo?key=abcdefg&q=%s,%s,itude.getLatitude(),itude.getLongitude();6. Log.i(URL,urlString);7. 8. /*新建HttpClient*/9. HttpClientclient=newDefaultHttpClient();10. /*采用GET方法*/11. HttpGetget=newHttpGet(urlString);12. try13. /*发起GET请求并获得返回数据*/14. HttpResponseresponse=client.execute(get);15. HttpEntityentity=response.getEntity();16. BufferedReaderbuffReader=newBufferedReader(newInputStreamReader(entity.getContent();17. StringBufferstrBuff=ne

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论