你好,游客 登录 注册 搜索
背景:
阅读新闻

Android GSM+CDMA基站定位

[日期:2012-06-15] 来源:Linux社区  作者:geniuseoe [字体:大 中 小]
所以部分童鞋的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接口获取经纬度,代码如下:
  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("http://www.google.com/loc/json");  
  7.                 JSONObject holder = new JSONObject();  
  8.   
  9.                 try {  
  10.                         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.                         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"

这个千万别搞混了,不然就获取不到信息了

linux
相关资讯       Android编程开发 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款