[地理位置] android 定位的几种模式介绍
[地理位置] android 定位的几种方式介绍367主题4听众1480积分管理员? ?? ???} else {? ?? ?? ?? ?tv1.setT
[地理位置] android 定位的几种方式介绍
367
主题
4
听众
1480
积分
管理员
![[地理位置] android 定位的几种模式介绍](//img.reader8.net/uploadfile/jiaocheng/2014018/2615/201401260915332222.gif)
![[地理位置] android 定位的几种模式介绍](//img.reader8.net/uploadfile/jiaocheng/2014018/2615/201401260915332222.gif)
![[地理位置] android 定位的几种模式介绍](//img.reader8.net/uploadfile/jiaocheng/2014018/2615/201401260915332223.gif)
? ?? ???} else {? ?? ?? ?? ?tv1.setText("无法获取地理信息");? ?? ???}
? ? }
(2)? ?? ? Android 基站定位:Android 基站定位只要明白了基站/WIFI定位的原理,自己实现基站/WIFI定位其实不难。基站定位一般有几种,第一种是利用手机附近的三个基站进行三角定位,由于每个基站的位置是固定的,利用电磁波在这三个基站间中转所需要时间来算出手机所在的坐标;第二种则是利用获取最近的基站的信息,其中包括基站 id,location area code、mobile country code、mobile network code和信号强度,将这些数据发送到google的定位web服务里,就能拿到当前所在的位置信息,误差一般在几十米到几百米之内。其中信号强度这个数据很重要,这里笔者就不多做解释了,直接给出一个文章,这个文章写的非常好,http://www.cnblogs.com/rayee/archive/2012/02/02/2336101.html(3)
? ?? ?Android Wifi定位:根据一个固定的WifiMAC地址,通过收集到的该Wifi热点的位置,然后访问网络上的定位服务以获得经纬度坐标。因为它和基站定位其实都需要使用网络,所以在Android也统称为Network方式。代码:public classWiFiInfoManager implements Serializable {
? ? private static final long serialVersionUID= -4582739827003032383L;
? ? private Context context;
? ? public WiFiInfoManager(Context context) {? ?? ???super();? ?? ???this.context = context;? ? }
? ? public WifiInfo getWifiInfo() {? ?? ???WifiManager manager = (WifiManager)context? ?? ?? ?? ?? ?.getSystemService(Context.WIFI_SERVICE);? ?? ???WifiInfo info = new WifiInfo();? ?? ???info.mac =manager.getConnectionInfo().getBSSID();? ?? ???Log.i("TAG", "WIFI MACis:" + info.mac);? ?? ???return info;? ? }
? ? public class WifiInfo {
? ?? ???public String mac;
? ?? ???public WifiInfo() {? ?? ?? ?? ?super();? ?? ???}? ? }
}上面是取到WIFI的mac地址的方法,下面是把地址发送给google服务器,代码如下public staticLocation getWIFILocation(WifiInfo wifi) {? ?? ???if (wifi == null) {? ?? ?? ?? ?Log.i("TAG", "wifiis null.");? ?? ?? ?? ?return null;? ?? ???}? ?? ???DefaultHttpClient client = newDefaultHttpClient();? ?? ???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");
? ?? ?? ?? ?JSONObject data;? ?? ?? ?? ?JSONArray array = new JSONArray();? ?? ?? ?? ?if (wifi.mac != null &&wifi.mac.trim().length() > 0) {? ?? ?? ?? ?? ? data = new JSONObject();? ?? ?? ?? ?? ?data.put("mac_address", wifi.mac);? ?? ?? ?? ?? ?data.put("signal_strength", 8);? ?? ?? ?? ?? ? data.put("age", 0);? ?? ?? ?? ?? ? array.put(data);? ?? ?? ?? ?}? ?? ?? ?? ?holder.put("wifi_towers",array);? ?? ?? ?? ?Log.i("TAG","request json:" + holder.toString());? ?? ?? ?? ?StringEntity se = newStringEntity(holder.toString());? ?? ?? ?? ?post.setEntity(se);? ?? ?? ?? ?HttpResponse resp =client.execute(post);? ?? ?? ?? ?int state =resp.getStatusLine().getStatusCode();? ?? ?? ?? ?if (state == HttpStatus.SC_OK) {? ?? ?? ?? ?? ? HttpEntity entity =resp.getEntity();? ?? ?? ?? ?? ? if (entity != null) {? ?? ?? ?? ?? ?? ???BufferedReader br = newBufferedReader(? ?? ?? ?? ?? ?? ?? ?? ?? ? newInputStreamReader(entity.getContent()));? ?? ?? ?? ?? ?? ???StringBuffer sb = newStringBuffer();? ?? ?? ?? ?? ?? ???String resute ="";? ?? ?? ?? ?? ?? ???while ((resute =br.readLine()) != null) {? ?? ?? ?? ?? ?? ?? ?? ?sb.append(resute);? ?? ?? ?? ?? ?? ???}? ?? ?? ?? ?? ?? ???br.close();
? ?? ?? ?? ?? ?? ???Log.i("TAG","response json:" + sb.toString());? ?? ?? ?? ?? ?? ???data = newJSONObject(sb.toString());? ?? ?? ?? ?? ?? ???data = (JSONObject)data.get("location");
? ?? ?? ?? ?? ?? ???Location loc = newLocation(? ?? ?? ?? ?? ?? ?? ?? ?? ?android.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());? ?? ?? ?? ?? ?? ???return loc;? ?? ?? ?? ?? ? } else {? ?? ?? ?? ?? ?? ???return null;? ?? ?? ?? ?? ? }? ?? ?? ?? ?} else {? ?? ?? ?? ?? ? Log.v("TAG", state +"");? ?? ?? ?? ?? ? return null;? ?? ?? ?? ?}
? ?? ???} catch (Exception e) {? ?? ?? ?? ?Log.e("TAG",e.getMessage());? ?? ?? ?? ?return null;? ?? ???}? ? }(3.1)而WIFI定位与基站定位的结合,笔者也在网上找到一个很好的文章,笔者对此就不做任何解释,直接给出网址:http://www.cnblogs.com/coffeegg/archive/2011/10/01/2197129.html(4)? ?? ???AGPS定位:AGPS(AssistedGPS:辅助全球卫星定位系统)是结合GSM或GPRS与传统卫星定位,利用基地台代送辅助卫星信息,以缩减GPS芯片获取卫星信号的延迟时间,受遮盖的室内也能借基地台讯号弥补,减轻GPS芯片对卫星的依赖度。和纯GPS、基地台三角定位比较,AGPS能提供范围更广、更省电、速度更快的定位服务,理想误差范围在10公尺以内,日本和美国都已经成熟运用AGPS于LBS服务(Location Based Service,基于位置的服务)。AGPS技术是一种结合了网络基站信息和GPS信息对移动台进行定位的技术,可以在GSM/GPRS、WCDMA和CDMA2000网络中使进行用。该技术需要在手机内增加GPS接收机模块,并改造手机的天线,同时要在移动网络上加建位置服务器、差分GPS基准站等设备。AGPS解决方案的优势主要体现在其定位精度上,在室外等空旷地区,其精度在正常的GPS工作环境下,可以达到10米左右,堪称目前定位精度最高的一种定位技术。该技术的另一优点为:首次捕获GPS信号的时间一般仅需几秒,不像GPS的首次捕获时间可能要2~3分钟