Android基站定位——三基站(多基站)定位(三)

这一篇基于:Android基站定位——单基站定位(二)

阐述几个概念:

基站:类似于WIFI热点,官方解释,移动通信系统中,连接固定部分与无线部分,并通过空中的无线传输与移动台相连的设备。基站即公用移动通信基站是无线电台站的一种形式,是指在一定的无线电覆盖区中,通过移动通信交换中心,与移动电话终端之间进行信息传递的无线电收发信电台。

单基站定位是指:通过手机获取当前连接到的基站信息,来确定用户的大概位置(用户可能在某个基站(手机当前连接的基站)发出的无线电覆盖区域中)。

三基站或多基站:通过手机获取附近区域的基站信息(不是用户当前连接的基站,得到的是一组基站信息),来确定用户的大概位置。

获取邻区基站信息

  1. // 获取邻区基站信息   
  2. List<NeighboringCellInfo> infos = mTelephonyManager.getNeighboringCellInfo();  
  3. StringBuffer sb = new StringBuffer("总数 : " + infos.size() + "\n");  
  4. for (NeighboringCellInfo info1 : infos) { // 根据邻区总数进行循环   
  5.     sb.append(" LAC : " + info1.getLac()); // 取出当前邻区的LAC   
  6.     sb.append(" CID : " + info1.getCid()); // 取出当前邻区的CID   
  7.     sb.append(" BSSS : " + (-113 + 2 * info1.getRssi()) + "\n"); // 获取邻区基站信号强度   
  8. }  
        // 获取邻区基站信息
        List<NeighboringCellInfo> infos = mTelephonyManager.getNeighboringCellInfo();
        StringBuffer sb = new StringBuffer("总数 : " + infos.size() + "\n");
        for (NeighboringCellInfo info1 : infos) { // 根据邻区总数进行循环
            sb.append(" LAC : " + info1.getLac()); // 取出当前邻区的LAC
            sb.append(" CID : " + info1.getCid()); // 取出当前邻区的CID
            sb.append(" BSSS : " + (-113 + 2 * info1.getRssi()) + "\n"); // 获取邻区基站信号强度
        }


注:中国联通的基本上获取不到附近的基站,我测的时候使用的是中国移动。

一、探索:

       1、我猜想请求参数的Json是这样组装的:     

  1. JSONObject json = new JSONObject();  
  2. json.put("version""1.1.0");  
  3. json.put("host""maps.google.com");  
  4. json.put("location_area_code""6338");  
  5. json.put("mobile_country_code""460");  
  6. json.put("mobile_network_code""0");  
  7. json.put("age"0);  
  8.   
  9. JSONArray array = new JSONArray();  
  10. JSONObject json1 = new JSONObject();  
  11. json1.put("cell_id""62291");  
  12. json1.put("signal_strength", -95);  
  13. array.put(json1);  
  14.   
  15. JSONObject json2 = new JSONObject();  
  16. json2.put("cell_id""62290");  
  17. json2.put("signal_strength", -101);  
  18. array.put(json2);  
  19.   
  20. json.put("cell_towers", array);  
        JSONObject json = new JSONObject();
        json.put("version", "1.1.0");
        json.put("host", "maps.google.com");
        json.put("location_area_code", "6338");
        json.put("mobile_country_code", "460");
        json.put("mobile_network_code", "0");
        json.put("age", 0);
        
        JSONArray array = new JSONArray();
        JSONObject json1 = new JSONObject();
        json1.put("cell_id", "62291");
        json1.put("signal_strength", -95);
        array.put(json1);
        
        JSONObject json2 = new JSONObject();
        json2.put("cell_id", "62290");
        json2.put("signal_strength", -101);
        array.put(json2);
        
        json.put("cell_towers", array);

           2、组拼好的JSON字符串:

  1. {  
  2.    "mobile_network_code":"0",  
  3.    "location_area_code":"6338",  
  4.    "host":"maps.google.com",  
  5.    "cell_towers":  
  6.        [  
  7.          {  
  8.             "signal_strength":-95,  
  9.             "cell_id":"62291"  
  10.          },  
  11.          {  
  12.              "signal_strength":-101,  
  13.              "cell_id":"62290"  
  14.           }  
  15.         ],  
  16.         "age":0,  
  17.         "mobile_country_code":"460",  
  18.         "version":"1.1.0"  
  19. }  
 {
    "mobile_network_code":"0",
    "location_area_code":"6338",
    "host":"maps.google.com",
    "cell_towers":
        [
          {
             "signal_strength":-95,
             "cell_id":"62291"
          },
          {
              "signal_strength":-101,
              "cell_id":"62290"
           }
         ],
         "age":0,
         "mobile_country_code":"460",
         "version":"1.1.0"
 }

       3、通过HTTP请求返回的JSON形式结果:

  1. {  
  2.  "location":  
  3.      {  
  4.          "latitude":"0.0",  
  5.          "longitude":"0.0",  
  6.          "address":  
  7.          {  
  8.              "city":"基站信息不存在,请从手机上读取正确的基站信息。",  
  9.              "country":"",  
  10.              "country_code":""  
  11.              ,"county":"",  
  12.              "postal_code":"",  
  13.              "region":"",  
  14.              "street":"",  
  15.              "street_number":""  
  16.           }  
  17.       },  
  18.       "access_token":"dummytoken"  
  19. }  
   {
    "location":
        {
            "latitude":"0.0",
            "longitude":"0.0",
            "address":
            {
                "city":"基站信息不存在,请从手机上读取正确的基站信息。",
                "country":"",
                "country_code":""
                ,"county":"",
                "postal_code":"",
                "region":"",
                "street":"",
                "street_number":""
             }
         },
         "access_token":"dummytoken"
   }


二、可行的方式:

        1、通过单个附近的基站信息定位:

        组装参数:

  1. /** 
  2.     * 获取JSON形式的基站信息 
  3.     * @param mcc 移动国家代码(中国的为460) 
  4.     * @param mnc 移动网络号码(中国移动为0,中国联通为1,中国电信为2);  
  5.     * @param lac 位置区域码 
  6.     * @param cid 基站编号 
  7.     * @param bsss 基站信号强度 
  8.     * @return json 
  9.     * @throws JSONException 
  10.     */  
  11.    private String getJsonCellPos(int mcc, int mnc, int lac, int cid, int bsss) throws JSONException {  
  12.        JSONObject jsonCellPos = new JSONObject();  
  13.        jsonCellPos.put("version""1.1.0");  
  14.        jsonCellPos.put("host""maps.google.com");  
  15.   
  16.        JSONArray array = new JSONArray();  
  17.        JSONObject json1 = new JSONObject();  
  18.        json1.put("location_area_code""" + lac + "");  
  19.        json1.put("mobile_country_code""" + mcc + "");  
  20.        json1.put("mobile_network_code""" + mnc + "");  
  21.        json1.put("age"0);  
  22.        json1.put("cell_id""" + cid + "");  
  23.        json1.put("signal_strength", bsss);  
  24.        array.put(json1);  
  25.   
  26.        jsonCellPos.put("cell_towers", array);  
  27.        return jsonCellPos.toString();  
  28.    }  
 /**
     * 获取JSON形式的基站信息
     * @param mcc 移动国家代码(中国的为460)
     * @param mnc 移动网络号码(中国移动为0,中国联通为1,中国电信为2); 
     * @param lac 位置区域码
     * @param cid 基站编号
     * @param bsss 基站信号强度
     * @return json
     * @throws JSONException
     */
    private String getJsonCellPos(int mcc, int mnc, int lac, int cid, int bsss) throws JSONException {
        JSONObject jsonCellPos = new JSONObject();
        jsonCellPos.put("version", "1.1.0");
        jsonCellPos.put("host", "maps.google.com");

        JSONArray array = new JSONArray();
        JSONObject json1 = new JSONObject();
        json1.put("location_area_code", "" + lac + "");
        json1.put("mobile_country_code", "" + mcc + "");
        json1.put("mobile_network_code", "" + mnc + "");
        json1.put("age", 0);
        json1.put("cell_id", "" + cid + "");
        json1.put("signal_strength", bsss);
        array.put(json1);

        jsonCellPos.put("cell_towers", array);
        return jsonCellPos.toString();
    }

       请求的JSON字符串:

  1. {  
  2.   "cell_towers":  
  3.       [  
  4.        {  
  5.            "mobile_network_code":"0",  
  6.            "location_area_code":"6338",  
  7.            "cell_id":"62291",  
  8.            "signal_strength":-95,  
  9.            "age":0,  
  10.            "mobile_country_code":"460"  
  11.         }  
  12.        ],  
  13.    "host":"maps.google.com",  
  14.    "version":"1.1.0"  
  15. }  
          {
            "cell_towers":
                [
                 {
                     "mobile_network_code":"0",
                     "location_area_code":"6338",
                     "cell_id":"62291",
                     "signal_strength":-95,
                     "age":0,
                     "mobile_country_code":"460"
                  }
                 ],
             "host":"maps.google.com",
             "version":"1.1.0"
          }

          返回JSON形式结果:

  1.         {  
  2.             "location":  
  3.             {  
  4.                 "latitude":"31.214667405",  
  5.                 "longitude":"121.59903152499999",  
  6.                 "address":  
  7.                 {  
  8.                     "city":"上海市浦东新区郭守敬路;上海奥威科技开发公司、科威国际技术转移中心公司、张江高科技园区热力中心[附近]",  
  9.                     "country":"",  
  10.                     "country_code":"",  
  11.                     "county":"",  
  12.                     "postal_code":"",  
  13.                     "region":"",  
  14.                     "street":"",  
  15.                     "street_number":""  
  16.                 }  
  17.            },  
  18.            "access_token":"dummytoken"  
  19.         }  
        {
            "location":
            {
                "latitude":"31.214667405",
                "longitude":"121.59903152499999",
                "address":
                {
                    "city":"上海市浦东新区郭守敬路;上海奥威科技开发公司、科威国际技术转移中心公司、张江高科技园区热力中心[附近]",
                    "country":"",
                    "country_code":"",
                    "county":"",
                    "postal_code":"",
                    "region":"",
                    "street":"",
                    "street_number":""
                }
           },
           "access_token":"dummytoken"
        }

 

        2、通过多个附近的基站信息定位:

              又一次猜想:

              请求JSON:

  1. {  
  2.    "cell_towers":  
  3.        [  
  4.         {  
  5.             "mobile_network_code":"0",  
  6.             "location_area_code":"6338",  
  7.             "cell_id":"62291",  
  8.             "signal_strength":-95,  
  9.             "age":0,  
  10.             "mobile_country_code":"460"  
  11.         },  
  12.         {  
  13.             "mobile_network_code":"0",  
  14.             "location_area_code":"6338",  
  15.             "cell_id":"62290",  
  16.             "signal_strength":-101,  
  17.             "age":1,  
  18.             "mobile_country_code":"460"  
  19.          }  
  20.         ],  
  21.         "host":"maps.google.com",  
  22.         "version":"1.1.0"  
  23. }  
         {
            "cell_towers":
                [
                 {
                     "mobile_network_code":"0",
                     "location_area_code":"6338",
                     "cell_id":"62291",
                     "signal_strength":-95,
                     "age":0,
                     "mobile_country_code":"460"
                 },
                 {
                     "mobile_network_code":"0",
                     "location_area_code":"6338",
                     "cell_id":"62290",
                     "signal_strength":-101,
                     "age":1,
                     "mobile_country_code":"460"
                  }
                 ],
                 "host":"maps.google.com",
                 "version":"1.1.0"
         }

 

              返回JSON:

  1. {  
  2.     "location":  
  3.     {  
  4.         "latitude":"31.21485922285714",  
  5.         "longitude":"121.59990774285711",  
  6.         "address":  
  7.         {  
  8.             "city":"上海市浦东新区郭守敬路276号;上海奥威科技开发公司、科威国际技术转移中心公司、张江高科技园区热力中心[附近]",  
  9.             "country":"",  
  10.             "country_code":"",  
  11.             "county":"",  
  12.             "postal_code":"",  
  13.             "region":"",  
  14.             "street":"",  
  15.             "street_number":""  
  16.          }  
  17.     },  
  18.     "access_token":"dummytoken"  
  19. }  
        {
            "location":
            {
                "latitude":"31.21485922285714",
                "longitude":"121.59990774285711",
                "address":
                {
                    "city":"上海市浦东新区郭守敬路276号;上海奥威科技开发公司、科威国际技术转移中心公司、张江高科技园区热力中心[附近]",
                    "country":"",
                    "country_code":"",
                    "county":"",
                    "postal_code":"",
                    "region":"",
                    "street":"",
                    "street_number":""
                 }
            },
            "access_token":"dummytoken"
        }

        结论:第三方服务器端可能有限制,每次只接受JSONArray中的第一个元素。如果要想一次性查找附近多个基站的经纬度及所在的地址,就只能编写for循环,一次一次的访问第三方的服务器。

 

        3、个人观点:所谓的三点定位或多点定位,只是让想知道用户当前位置的人多了一个选择而已。三点定位得到的是三个点,并非是一个比较准确的点。

三、测试网址:http://www.minigps.net/map3.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值