获取电信cdma基站经纬度

public void onClick(View v) {
    // TODO Auto-generated method stub
    tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
    //int type = tm.getNetworkType();
    //if (type ==TelephonyManager.NETWORK_TYPE_CDMA) {
        location = (CdmaCellLocation) tm.getCellLocation();
        if(location == null)
            return;
        int sid = location.getSystemId();//系统标识  mobileNetworkCode
        int bid = location.getBaseStationId();//基站小区号  cellId
        int nid = location.getNetworkId();//网络标识  locationAreaCode
        
        Log.i(\"sid:\", \"\" + sid);
        Log.i(\"bid:\", \"\" + bid);
        Log.i(\"nid:\", \"\" + nid);
        ArrayList<CellIDInfo> CellID = new ArrayList<CellIDInfo>();
        CellIDInfo info = new CellIDInfo();
        info.cellId = bid;
        info.locationAreaCode = nid;
        info.mobileNetworkCode = String.valueOf(sid);
        info.mobileCountryCode = tm.getNetworkOperator().substring(0, 3);
        info.mobileCountryCode = tm.getNetworkOperator().substring(3, 5);
        info.radioType = \"cdma\";
        CellID.add(info);
        Log.d(\"cellId:\", \"\" + info.cellId);
        Log.d(\"locationAreaCode:\", \"\" + info.locationAreaCode);
        Log.d(\"mobileNetworkCode:\", info.mobileNetworkCode);
        Log.d(\"mobileCountryCode:\", info.mobileCountryCode);
        Location loc = callGear(CellID);
        
        if (loc !=null) 
            mTextView.setText(\"纬度:\" + loc.getLatitude() + \"\\n经度:\" + loc.getLongitude());
    //}// end if
}// end onclick
  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;
        }

 

转载于:https://www.cnblogs.com/topwang-com/archive/2012/12/19/2824425.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值