分享
分销 收藏 举报 申诉 / 16

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

  • 上传人:二***
  • 文档编号:4711242
  • 上传时间:2024-10-10
  • 格式:DOC
  • 页数:16
  • 大小:85.04KB
  • 下载积分:5 金币
  • 配套讲稿:

    如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。

    特殊限制:

    部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。

    关 键  词:
    移动 联通 电信 获取 基站 数据库 专项 方案
    资源描述:
    移动联通电信获取基站数据库方案 在谷歌API里提供了基站信息获取类TelephonyManager,经过其方法getCellLocation得到CellLocation即可获取到基站相关信息 但CellLocation是个抽象类,所以在具体使用时需要判定接入网络制式来用其子类CdmaCellLocation或GsmCellLocation 来强转 CdmaCellLocation对应CDMA网,GsmCellLocation对应GSM网 三大网络运行商网络制式对应以下: 移动2G 网 --> GSM 移动3G 网 --> TD-SCDMA 电信2G 网 --> CDMA 电信3G 网 --> CDMA 联通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. public static ArrayList<CellIDInfo> getCellIDInfo(Context context) throws Exception{   2.            3.         TelephonyManager manager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);   4.            5.         ArrayList<CellIDInfo> CellID = new ArrayList<CellIDInfo>();   6.         CellIDInfo currentCell = new CellIDInfo();   7.    8.         int type = manager.getNetworkType();   9.         Log.d(TAG, "getCellIDInfo-->         NetworkType = " + type);   10.         int phoneType = manager.getPhoneType();   11.         Log.d(TAG, "getCellIDInfo-->         phoneType = " + phoneType);   12.            13.         if (type == TelephonyManager.NETWORK_TYPE_GPRS              // GSM网   14.                 || type == TelephonyManager.NETWORK_TYPE_EDGE   15.                 || type == TelephonyManager.NETWORK_TYPE_HSDPA)   16.         {   17.             GsmCellLocation gsm = ((GsmCellLocation) manager.getCellLocation());   18.             if (gsm == null)   19.             {   20.                 Log.e(TAG, "GsmCellLocation is null!!!");   21.                 return null;   22.             }   23.                    24.    25.             int lac = gsm.getLac();   26.             String mcc = manager.getNetworkOperator().substring(0, 3);   27.             String mnc = manager.getNetworkOperator().substring(3, 5);   28.             int cid = 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.             List<NeighboringCellInfo> list = manager.getNeighboringCellInfo();   41.             int size = list.size();   42.             for (int i = 0; i < size; i++) {   43.    44.                 CellIDInfo info = new CellIDInfo();   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.         }else if (type == TelephonyManager.NETWORK_TYPE_CDMA        // 电信cdma网   54.                 || type == TelephonyManager.NETWORK_TYPE_1xRTT   55.                 || type == TelephonyManager.NETWORK_TYPE_EVDO_0   56.                 || type == TelephonyManager.NETWORK_TYPE_EVDO_A)   57.         {   58.                59.             CdmaCellLocation cdma = (CdmaCellLocation) manager.getCellLocation();      60.             if (cdma == null)   61.             {   62.                 Log.e(TAG, "CdmaCellLocation is null!!!");   63.                 return null;   64.             }   65.                66.             int lac = cdma.getNetworkId();   67.             String mcc = manager.getNetworkOperator().substring(0, 3);   68.             String mnc = String.valueOf(cdma.getSystemId());   69.             int cid = 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.             List<NeighboringCellInfo> list = manager.getNeighboringCellInfo();   82.             int size = list.size();   83.             for (int i = 0; i < size; i++) {   84.    85.                 CellIDInfo info = new CellIDInfo();   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.         return CellID;   96.                97.     }   从谷歌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表中 最终经过谷歌提供gear接口获取经纬度,代码以下: Html代码  1. public static Location callGear(List<CellIDInfo> cellID) {   2.             if (cellID == null || cellID.size() == 0)    3.                     return null;   4.                5.             DefaultHttpClient client = new DefaultHttpClient();   6.                 HttpPost post = new HttpPost("");   7.                 JSONObject holder = new JSONObject();   8.    9.                 try {   10.                         holder.put("version", "1.1.0");   11.                         holder.put("host", "maps.谷歌.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.                         else   19.                                 holder.put("address_language", "en_US");   20.                            21.                         JSONObject data,current_data;   22.    23.                         JSONArray array = new JSONArray();   24.                            25.                         current_data = new JSONObject();   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 (int i = 1; i < cellID.size(); i++) {   37.                              data = new JSONObject();   38.                              data.put("cell_id", cellID.get(i).cellId);   39.                              data.put("location_area_code", cellID.get(i).locationAreaCode);   40.                              data.put("mobile_country_code", cellID.get(i).mobileCountryCode);   41.                              data.put("mobile_network_code", cellID.get(i).mobileNetworkCode);   42.                              data.put("age", 0);   43.                              array.put(data);   44.                             }   45.                            }   46.    47.                            48.                            49.                            50.                         holder.put("cell_towers", array);   51.                                                    52.                         StringEntity se = new StringEntity(holder.toString());   53.                         Log.e("Location send", holder.toString());   54.                         post.setEntity(se);   55.                         HttpResponse resp = client.execute(post);   56.    57.                         HttpEntity entity = resp.getEntity();   58.    59.                         BufferedReader br = new BufferedReader(   60.                                         new InputStreamReader(entity.getContent()));   61.                         StringBuffer sb = new StringBuffer();   62.                         String result = br.readLine();   63.                         while (result != null) {   64.                                 Log.e("Locaiton reseive-->", result);   65.                                 sb.append(result);   66.                                 result = br.readLine();   67.                         }   68.                            69.                         data = new JSONObject(sb.toString());   70.                          71.                         data = (JSONObject) data.get("location");   72.    73.                         Location loc = new Location(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.                         return loc;   79.                 } catch (JSONException e) {   80.                         e.printStackTrace();   81.                         return null;   82.                 } catch (UnsupportedEncodingException e) {   83.                         e.printStackTrace();   84.                 } catch (ClientProtocolException e) {   85.                         e.printStackTrace();   86.                 } catch (IOException e) {   87.                         e.printStackTrace();   88.                 }   89.    90.                 return null;   91.         }   大家注意看这行holder.put("radio_type", cellID.get(0).radioType); GSM就用"gsm",CDMA就用"cdma" 这个千万别搞混了,不然就获取不到信息了 值得一提是C网获取基站再定位那偏差不是通常大,是恨大,快要1千米了,大约是C网基站较少缘故吧 最终经过经纬度获取地理位置信息,代码以下: Java代码  1. public static  String getAddress(Location itude) throws Exception {   2.         String resultString = "";   3.     4.         /** 这里采取get方法,直接将参数加到URL上 */   5.         String urlString = String.format(",%s", itude.getLatitude(), itude.getLongitude());   6.         Log.i("URL", urlString);   7.     8.         /** 新建HttpClient */   9.         HttpClient client = new DefaultHttpClient();   10.         /** 采取GET方法 */   11.         HttpGet get = new HttpGet(urlString);   12.         try {   13.             /** 提议GET请求并取得返回数据 */   14.             HttpResponse response = client.execute(get);   15.             HttpEntity entity = response.getEntity();   16.             BufferedReader buffReader = new BufferedReader(new InputStreamReader(entity.getContent()));   17.             StringBuffer strBuff = new StringBuffer();   18.             String result = 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.                 JSONObject jsonobject = new JSONObject(resultString);   29.                 JSONArray jsonArray = new JSONArray(jsonobject.get("Placemark").toString());   30.                 resultString = "";   31.                 for (int i = 0; i < jsonArray.length(); i++) {   32.                     resultString = jsonArray.getJSONObject(i).getString("address");   33.                 }   34.             }   35.         } catch (Exception e) {   36.             throw new Exception("获取物理位置出现错误:" + e.getMessage());   37.         } finally {   38.             get.abort();   39.             client = null;   40.         }   41.     42.         return resultString;   43.     }   在获取地理位置这个location实际上应该传入纠偏后location,本文暂不做此处理,所以得到地理信息位置是偶偏差,大家注意 最终附上截图: PS: 需要基站数据能够联络:QQ:
    展开阅读全文

    开通VIP折扣优惠下载文档

    提示  咨信网声明:本文档由用户上传并分享,仅供学习交流、研究之用,未经授权,严禁复制、发行、汇编、翻译或网络传播等,侵权必究。

    咨信网小贴示:
    1、浏览或下载可查看了解,请点击【咨信网告知】。
    2、下载文件中如有侵权或不适当内容,将立即纠正。
    3、如果因为网速或其他原因下载失败请重新下载,重复下载[60天内]不扣币。
    4、开具发票登录电脑端申请,请点击【索取发票】。

    咨信网客服组:【微信客服】

    自信AI创作助手
    关于本文
    本文标题:移动联通电信获取基站数据库的专项方案.doc
    链接地址:https://www.zixin.com.cn/doc/4711242.html

    Copyright ©2010-2026   All Rights Reserved  宁波自信网络信息技术有限公司 版权所有   |  客服电话:0574-28810668    微信客服:咨信网客服    投诉电话:18658249818   

    违法和不良信息举报邮箱:help@zixin.com.cn    文档合作和网站合作邮箱:fuwu@zixin.com.cn    意见反馈和侵权处理邮箱:1219186828@qq.com   | 证照中心

    12321jubao.png12321网络举报中心 电话:010-12321  jubao.png中国互联网举报中心 电话:12377   gongan.png浙公网安备33021202000488号  icp.png浙ICP备2021020529号-1 浙B2-20240490   


    关注我们 :微信公众号  抖音  微博  LOFTER               

    自信网络  |  ZixinNetwork