Android获取基站坐标代码
2012-05-06 21:14
197 查看
package com.su.station; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import org.apache.http.HttpEntity; import org.apache.http.HttpResponse; import org.apache.http.client.methods.HttpPost; import org.apache.http.entity.StringEntity; import org.apache.http.impl.client.DefaultHttpClient; import org.json.JSONArray; import org.json.JSONObject; import android.app.Activity; import android.content.Context; import android.location.Location; import android.location.LocationManager; import android.os.Bundle; import android.telephony.TelephonyManager; import android.telephony.gsm.GsmCellLocation; import android.util.Log; import android.widget.Toast; public class TestStationLocationActivity extends Activity { private static final String TAG = "TestStationLocationActivity"; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); Location location = getportLocation(); location.getLongitude(); Toast.makeText(this, location.getLatitude()+location.getLatitude()+"", 100).show(); } private Location getportLocation() { Location loc = null ; TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); BufferedReader br = null; try { GsmCellLocation gcl = (GsmCellLocation) tm.getCellLocation(); if (null == gcl) { return null; } int cid = gcl.getCid(); int lac = gcl.getLac(); int mcc = Integer.valueOf(tm.getNetworkOperator().substring(0,3)); int mnc = Integer.valueOf(tm.getNetworkOperator().substring(3,5)); JSONObject holder = new JSONObject(); holder.put("version", "1.1.0"); holder.put("host", "maps.google.com"); holder.put("request_address", true); JSONArray array = new JSONArray(); JSONObject data = new JSONObject(); data.put("cell_id", cid); data.put("location_area_code", lac); data.put("mobile_country_code", mcc); data.put("mobile_network_code", mnc); array.put(data); holder.put("cell_towers", array); DefaultHttpClient client = new DefaultHttpClient(); HttpPost post = new HttpPost("http://www.google.com/loc/json"); StringEntity se = new StringEntity(holder.toString()); post.setEntity(se); HttpResponse resp = client.execute(post); if (resp.getStatusLine().getStatusCode() == 200) { HttpEntity entity = resp.getEntity(); br = new BufferedReader(new InputStreamReader(entity.getContent())); StringBuffer sb = new StringBuffer(); String result = br.readLine(); while (result != null) { sb.append(result); result = br.readLine(); } JSONObject data_ = new JSONObject(sb.toString()); data_ = (JSONObject) data_.get("location"); loc = new Location(LocationManager.NETWORK_PROVIDER); loc.setLatitude((Double) data_.get("latitude")); loc.setLongitude((Double) data_.get("longitude")); Log.i(TAG, "latitude : " + loc.getLatitude() + " longitude : " + loc.getLongitude()); return loc; } return null; } catch (Exception e) { android.util.Log.e(TAG, "network get the latitude and longitude ocurr Exception error", e); } finally { if (null != br) { try { br.close(); } catch (IOException e) { android.util.Log.e(TAG, "network get the latitude and longitude when closed BufferedReader ocurr IOException error", e); } } } return loc; } }
相关文章推荐
- Android获取基站坐标代码
- Android获取基站坐标代码
- Android获取基站坐标代码
- Android获取基站坐标代码
- android手机获取gps和基站的经纬度地址实现代码
- 通过android手机内置GPS获取平面直角坐标和高斯坐标的原理(附代码)
- Android 用代码获取基站号(cell)和小区号(lac)
- android手机获取gps和基站的经纬度地址实现代码
- Android代码中如何获取控件宽高
- Android Service获取当前位置(GPS+基站)
- AndroidStuido版本控制--误删代码或做了大量修改从新从GitHub上获取
- android 获取控件在屏幕里的坐标
- Android中的坐标系以及获取坐标的方法
- android 使用LocationClient获取精度,纬度坐标
- ANDROID设备获取IMEI,手机号码等常用代码片段
- [Android] 代码获取手机系统类型(小米MIUI、华为EMUI、魅族FLYME)
- Android 获取无线蓝牙MAC信息代码
- Android 使用 DowanloadManager 实现下载并获取下载进度实例代码
- android客户端从服务器端获取json数据并解析的实现代码
- Android获取控件坐标为0的原因及取得控件位置和两控件距离的方法