通过SIM卡获取GPS,android基站定位原理
TelephonyManager telManager=(TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
		GsmCellLocation glc=(GsmCellLocation) telManager.getCellLocation();
		int cid=glc.getCid();///gsm cell id, -1 if unknown, 0xffff max legal value 基站ID号
		int lac=glc.getLac();//写入区域代码
		String strOperator=telManager.getNetworkOperator();
		
		int mcc=Integer.valueOf(strOperator.substring(0, 3));//写入当前城市代码
		int mnc=Integer.valueOf(strOperator.substring(3, 5));//写入网络代码
		String getNumber="";
		getNumber+=("cid:"+cid+"\n");
		getNumber+=("cid:"+lac+"\n");
		getNumber+=("cid:"+mcc+"\n");
		getNumber+=("cid:"+mnc+"\n");
		
		try {
			JSONObject jObject=new JSONObject();
			jObject.put("version", "1.1.0");
			jObject.put("host", "maps.google.com");
			jObject.put("request_address", true);
			if(mcc==460)
				jObject.put("address_language","zh_CN");
			else
				jObject.put("address_language", "en_US");
			
			JSONArray jArray=new JSONArray();
			JSONObject jData=new JSONObject();
			jData.put("cell_id", cid);
			jData.put("location_area_code", lac);
			jData.put("mobile_country_code", mcc);
			jData.put("mobile_network_code", mnc);//
			jArray.put(jData);
			jObject.put("cell_towers",jArray);
			DefaultHttpClient client=new DefaultHttpClient();
			HttpPost post=new HttpPost("http://www.google.com/loc/json");
			StringEntity se=new StringEntity(jObject.toString());
			post.setEntity(se);
			
			HttpResponse resp=client.execute(post);
			BufferedReader br=null;
			if(resp.getStatusLine().getStatusCode()==HttpStatus.SC_OK){
				br=new BufferedReader(new InputStreamReader(resp.getEntity().getContent()));
				StringBuffer sb=new StringBuffer();
				
				String result=br.readLine();
				while(result!=null)
				{
					sb.append(getNumber);
					sb.append(result);
					result=br.readLine();
				}
				
				String s=sb.toString();
				s=s.substring(s.indexOf("{"));
				btn.setText(s);
				JSONObject jo=new JSONObject(s);
				
				String values="";
				JSONObject arr= jo.getJSONObject("location");
				String lat= arr.get("latitude").toString();
				String lon=arr.getString("longitude").toString();
				
				
				Toast.makeText(getApplicationContext(), "经度:"+lon+" 纬度:"+lat,1).show();
				
			}
		} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (UnsupportedEncodingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (ClientProtocolException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
最后还要加入网络访问权限
 <uses-permission android:name="android.permission.INTERNET"></uses-permission>
 <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"></uses-permission>



 

阅读更多
想对作者说点什么? 我来说一句

GPS和RTK的基本知识

RTSS

oqqENvY12 oqqENvY12

2017-06-16 07:38:04

阅读数:1493

没有更多推荐了,返回首页

不良信息举报

通过SIM卡获取GPS,android基站定位原理

最多只允许输入30个字

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭