博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
获取电信cdma基站经纬度
阅读量:4710 次
发布时间:2019-06-10

本文共 5612 字,大约阅读时间需要 18 分钟。

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
CellID = new ArrayList
(); 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
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

你可能感兴趣的文章
解决在vue中,自用mask模态框出来后,下层的元素依旧可以滑动的问题
查看>>
SSH加固
查看>>
python 二维字典
查看>>
实验吧之【天下武功唯快不破】
查看>>
2019-3-25多线程的同步与互斥(互斥锁、条件变量、读写锁、自旋锁、信号量)...
查看>>
win7-64 mysql的安装
查看>>
dcm4chee 修改默认(0002,0013) ImplementationVersionName
查看>>
maven3在eclipse3.4.2中创建java web项目
查看>>
POJ 2378 Tree Cutting(树形DP,水)
查看>>
UVA 116 Unidirectional TSP (白书dp)
查看>>
cnblog!i'm coming!
查看>>
fatal: remote origin already exists.
查看>>
LeetCode 242. Valid Anagram
查看>>
JSP表单提交乱码
查看>>
如何适应现代雇佣关系
查看>>
团队项目(第五周)
查看>>
JdbcTemplate
查看>>
第一次使用maven记录
查看>>
SharePoint服务器端对象模型 之 使用CAML进展数据查询
查看>>
Building Tablet PC Applications ROB JARRETT
查看>>