移动联通电信获取基站数据库的方案.doc

上传人:jian****018 文档编号:9910223 上传时间:2020-04-08 格式:DOC 页数:12 大小:85.50KB
返回 下载 相关 举报
移动联通电信获取基站数据库的方案.doc_第1页
第1页 / 共12页
移动联通电信获取基站数据库的方案.doc_第2页
第2页 / 共12页
移动联通电信获取基站数据库的方案.doc_第3页
第3页 / 共12页
点击查看更多>>
资源描述
移动联通电信获取基站数据库的方案在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(http:/www.google.com/loc/json);7. JSONObjectholder=newJSONObject();8. 9. try10. holder.put(version,1.1.0);11. holder.put(host,maps.google.com);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(http:/maps.google.cn/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=newStringBuffer();18. Stringresult=null;19. while(result=buffReader.readLine()!=null)20. strBuff.append(result);21. 22. resultString=strBuff.toString();23. 24. Log.e(resultAdress-,resultString);25. 26. /*解析JSON数据,获得物理地址*/27. if(resultString!=null&resultString.length()0)28. JSONObjectjsonobject=newJSONObject(resultString);29. JSONArrayjsonArray=newJSONArray(jsonobject.get(Placemark).toString();30. resultString=;31. for(inti=0;ijsonArray.length();i+)32. resultString=jsonArray.getJSONObject(i).getString(address);33. 34. 35. catch(Exceptione)36. thrownewException(获取物理位置出现错误:+e.getMessage();37. finally38. get.abort();39. client=null;40. 41. 42. returnresultString;43. 在获取地理位置的这个location事实上应该传入纠偏后的location,本文暂不做此处理,所以得到的地理信息位置是偶偏差的,大家注意最后附上截图:PS:需要基站数据的可以联系:QQ:742631333
展开阅读全文
相关资源
相关搜索

当前位置:首页 > 办公文档 > 解决方案


copyright@ 2023-2025  zhuangpeitu.com 装配图网版权所有   联系电话:18123376007

备案号:ICP2024067431-1 川公网安备51140202000466号


本站为文档C2C交易模式,即用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知装配图网,我们立即给予删除!