推荐阅读:
浅析Android手机卫士sim卡绑定
深入浅析Android手机卫士保存密码时进行md5加密
详解Android 手机卫士设置向导页面
浅析Android手机卫士关闭自动更新
浅析Android手机卫士自定义控件的属性
浅析Android手机卫士读取联系人
浅析Android手机卫士接收短信指令执行相应 *** 作
手机定位的三种方式:网络定位,基站定位,GPS定位
网络定位,手机连上wifi 2g 3g的时候,手机会有一个ip,误差很大
基站定位,精确度与基站的多少有关,几十米到几公里的误差
GPS定位,至少需要三颗卫星才能定位,在空旷的地方准确
手机使用A-GPS需要网络来辅助定位,定位速度快,网络记录了上次的卫星轨道,
获取LocationManager对象,通过getSystemService(LOCATION_SERVICE)
调用LocationManager对象的requestLocationUpdates()方法,请求位置更新,参数:
定位方式(“gps”),更新时间(60000),更新距离(50),LocationListener对象
LocationListener是一个接口,需要做它的实现类
定义MyLocationListener实现LocationListener,实现它下面的方法
onLocationChanged(),当位置改变的时候回调,传递进来一个Location对象
调用location对象的getLongitude()方法,得到经度
调用Location对象的getLatitude()方法,得到维度
调用Location对象的getAccuracy()方法,得到精确度
onStatusChanged(),当状态改变的时候回调,关闭 开启
onProvIDerEnabled(),当某一个位置提供者可用了
onProvIDerDisabled(),当某一个位置提供者不可用了
当activity销毁的时候,取消监听位置
重写activity的onDestroy()方法
调用LocationManager对象的removeUpdates(),取消监听,参数:LocationListener对象
把LocationListener对象置为null,垃圾回收
需要的权限
androID.permission.ACCESS_FINE_LOCATION 获取精准位置
androID.permission.ACCESS_COARSE_LOCATION 获取粗略的位置
androID.permission.ACCESS_MOCK_LOCATION 获取模拟的位置(模拟器开发的时候)
模拟器上,ddms里面发送以下位置,才能显示
国家对坐标进行了加偏处理,变成火星坐标,需要国家测绘局的插件,网上有火星坐标转换代码
package com.tsh.mylocation;import androID.app.Activity;import androID.location.Location;import androID.location.LocationListener;import androID.location.LocationManager;import androID.os.Bundle;import androID.vIEw.Menu;import androID.vIEw.MenuItem;import androID.Widget.Toast;public class MainActivity extends Activity {private LocationManager lm;private LocationListener Listener;@OverrIDeprotected voID onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentVIEw(R.layout.activity_main);//获取位置管理器lm=(LocationManager) getSystemService(LOCATION_SERVICE);Listener=new MyLocationListener();lm.requestLocationUpdates("gps",Listener);}private class MyLocationListener implements LocationListener{@OverrIDepublic voID onLocationChanged(Location location) {//获取经度String longitude="经度:"+location.getLongitude();String latitude="纬度:"+location.getLatitude();String acc="精确度:"+location.getAccuracy();Toast.makeText(MainActivity.this,longitude+latitude+acc,1).show();}@OverrIDepublic voID onStatusChanged(String provIDer,int status,Bundle extras) {}@OverrIDepublic voID onProvIDerEnabled(String provIDer) {}@OverrIDepublic voID onProvIDerDisabled(String provIDer) {}}}
以上所述是小编给大家介绍的AndroID手机卫士手机定位的原理,希望对大家有所帮助!
总结以上是内存溢出为你收集整理的浅析Android手机卫士手机定位的原理全部内容,希望文章能够帮你解决浅析Android手机卫士手机定位的原理所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)