这一篇基于:Android基站定位——单基站定位(二)
阐述几个概念:
基站:类似于WIFI热点,官方解释,移动通信系统中,连接固定部分与无线部分,并通过空中的无线传输与移动台相连的设备。基站即公用移动通信基站是无线电台站的一种形式,是指在一定的无线电覆盖区中,通过移动通信交换中心,与移动电话终端之间进行信息传递的无线电收发信电台。
单基站定位是指:通过手机获取当前连接到的基站信息,来确定用户的大概位置(用户可能在某个基站(手机当前连接的基站)发出的无线电覆盖区域中)。
三基站或多基站:通过手机获取附近区域的基站信息(不是用户当前连接的基站,得到的是一组基站信息),来确定用户的大概位置。
获取邻区基站信息:
- // 获取邻区基站信息
- 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"); // 获取邻区基站信号强度
- }
// 获取邻区基站信息
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是这样组装的:
- 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);
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字符串:
- {
- "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"
- }
{
"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形式结果:
- {
- "location":
- {
- "latitude":"0.0",
- "longitude":"0.0",
- "address":
- {
- "city":"基站信息不存在,请从手机上读取正确的基站信息。",
- "country":"",
- "country_code":""
- ,"county":"",
- "postal_code":"",
- "region":"",
- "street":"",
- "street_number":""
- }
- },
- "access_token":"dummytoken"
- }
{
"location":
{
"latitude":"0.0",
"longitude":"0.0",
"address":
{
"city":"基站信息不存在,请从手机上读取正确的基站信息。",
"country":"",
"country_code":""
,"county":"",
"postal_code":"",
"region":"",
"street":"",
"street_number":""
}
},
"access_token":"dummytoken"
}
二、可行的方式:
1、通过单个附近的基站信息定位:
组装参数:
- /**
- * 获取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形式的基站信息
* @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字符串:
- {
- "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"
- }
{
"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形式结果:
- {
- "location":
- {
- "latitude":"31.214667405",
- "longitude":"121.59903152499999",
- "address":
- {
- "city":"上海市浦东新区郭守敬路;上海奥威科技开发公司、科威国际技术转移中心公司、张江高科技园区热力中心[附近]",
- "country":"",
- "country_code":"",
- "county":"",
- "postal_code":"",
- "region":"",
- "street":"",
- "street_number":""
- }
- },
- "access_token":"dummytoken"
- }
{
"location":
{
"latitude":"31.214667405",
"longitude":"121.59903152499999",
"address":
{
"city":"上海市浦东新区郭守敬路;上海奥威科技开发公司、科威国际技术转移中心公司、张江高科技园区热力中心[附近]",
"country":"",
"country_code":"",
"county":"",
"postal_code":"",
"region":"",
"street":"",
"street_number":""
}
},
"access_token":"dummytoken"
}
2、通过多个附近的基站信息定位:
又一次猜想:
请求JSON:
- {
- "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"
- }
{
"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:
- {
- "location":
- {
- "latitude":"31.21485922285714",
- "longitude":"121.59990774285711",
- "address":
- {
- "city":"上海市浦东新区郭守敬路276号;上海奥威科技开发公司、科威国际技术转移中心公司、张江高科技园区热力中心[附近]",
- "country":"",
- "country_code":"",
- "county":"",
- "postal_code":"",
- "region":"",
- "street":"",
- "street_number":""
- }
- },
- "access_token":"dummytoken"
- }
{
"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、个人观点:所谓的三点定位或多点定位,只是让想知道用户当前位置的人多了一个选择而已。三点定位得到的是三个点,并非是一个比较准确的点。