一、LocationManager LocationMangager,位置管理器
要想操作定位相关设备,必须先定义个 LocationManager
我们可以通过如下代码创建 LocationManger 对象
LocationManger locationManager=(LocationManager)this
getSystemService(Context
LOCATION_SERVICE); 二、LocationListener LocationListener,位置监听,监听位置变化,监听设备开关与状态
private LocationListener locationListener=new LocationListener() { /** * 位置信息变化时触发 */ public void onLocationChanged(Location location) { updateView(location); Log
i(TAG, "时间:"+location
getTime()); Log
i(TAG, "经度:"+location
getLongitude()); Log
i(TAG, "纬度:"+location
getLatitude()); Log
i(TAG, "海拔:"+location
getAltitude()); } /** * GPS 状态变化时触发 */ public void onStatusChanged(String provider, int status, Bundle extras) { switch (status) { //GPS 状态为可见时 case LocationProvider
AVAILABLE: Log
i(TAG, "当前 GPS 状态为可见状态"); break; //GPS 状态为服务区外时