首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > 移动开发 >

CDMA基站定位获取中纬度

2012-07-28 
CDMA基站定位获取经纬度【原创】CDMA基站定位获取经纬度本贴最初原创地址:http://www.cmd100.com/bbs/forum-

CDMA基站定位获取经纬度

【原创】CDMA基站定位获取经纬度
本贴最初原创地址:
http://www.cmd100.com/bbs/forum-viewthread-tid-5325-fromuid-9.html


这几天在做基站定位,发觉CDMA的基站定位在网上资料很少。经过漫长的摸索,其中的小小收获给大家分享一下!
这个是CDMA中国电信的基站定位获取经纬度的源码及测试截图!在模拟器中用似乎不行,模拟器的网络不是CDMA的。有知道的请指点指点!

主要代码:

?

?

?

调用google gears的方法,该方法调用gears来获取经纬度 代码:

?

Java code//调用google gears的方法,该方法调用gears来获取经纬度         private Location callGear(ArrayList<CellIDInfo> cellID) {            if (cellID == null)                     return null;                        DefaultHttpClient client = new DefaultHttpClient();                HttpPost post = new HttpPost(                                "http://www.google.com/loc/json");                JSONObject holder = new JSONObject();                try {                        holder.put("version", "1.1.0");                        holder.put("host", "maps.google.com");                        holder.put("home_mobile_country_code", cellID.get(0).mobileCountryCode);                        holder.put("home_mobile_network_code", cellID.get(0).mobileNetworkCode);                        holder.put("radio_type", cellID.get(0).radioType);                        holder.put("request_address", true);                        if ("460".equals(cellID.get(0).mobileCountryCode))                                 holder.put("address_language", "zh_CN");                        else                                holder.put("address_language", "en_US");                                                JSONObject data,current_data;                        JSONArray array = new JSONArray();                                                current_data = new JSONObject();                        current_data.put("cell_id", cellID.get(0).cellId);                        current_data.put("location_area_code", cellID.get(0).locationAreaCode);                        current_data.put("mobile_country_code", cellID.get(0).mobileCountryCode);                        current_data.put("mobile_network_code", cellID.get(0).mobileNetworkCode);                        current_data.put("age", 0);                        current_data.put("signal_strength", -60);                        current_data.put("timing_advance", 5555);                        array.put(current_data);                                                holder.put("cell_towers", array);                                                                        StringEntity se = new StringEntity(holder.toString());                        Log.e("Location send", holder.toString());                        post.setEntity(se);                        HttpResponse resp = client.execute(post);                        HttpEntity entity = resp.getEntity();                        BufferedReader br = new BufferedReader(                                        new InputStreamReader(entity.getContent()));                        StringBuffer sb = new StringBuffer();                        String result = br.readLine();                        while (result != null) {                                Log.e("Locaiton reseive", result);                                sb.append(result);                                result = br.readLine();                        }                        data = new JSONObject(sb.toString());                        Log.d("-", sb.toString());                        data = (JSONObject) data.get("location");                        Location loc = new Location(LocationManager.NETWORK_PROVIDER);                        loc.setLatitude((Double) data.get("latitude"));                        loc.setLongitude((Double) data.get("longitude"));                        loc.setAccuracy(Float.parseFloat(data.get("accuracy").toString()));                        loc.setTime( System.currentTimeMillis());//AppUtil.getUTCTime());                        return loc;                } catch (JSONException e) {                        e.printStackTrace();                        return null;                } catch (UnsupportedEncodingException e) {                        e.printStackTrace();                } catch (ClientProtocolException e) {                        e.printStackTrace();                } catch (IOException e) {                        e.printStackTrace();                }                Log.d("-", "null 1");                return null;        }?

?

?

在弄这个的时候不要忘了加权限噢!

Java code
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"></uses-permission>
<uses-permission android:name="android.permission.READ_PHONE_STATE"></uses-permission>
<uses-permission android:name="android.permission.INTERNET"></uses-permission>

1 楼 lishali12345 2011-08-26   文章中好像有个错误:
引用info.mobileCountryCode = tm.getNetworkOperator().substring(0, 3); 
                                info.mobileCountryCode = tm.getNetworkOperator().substring(3, 5);
这两句代码好像有问题吧,应该是值需要第一行吧

热点排行