二、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状态为服务区外时
case LocationProvider.OUT_OF_SERVICE:
Log.i(TAG, "当前GPS状态为服务区外状态");
break;
//GPS状态为暂停服务时
case LocationProvider.TEMPORARILY_UNAVAILABLE:
Log.i(TAG, "当前GPS状态为暂停服务状态");
break;
}
}
/**
* GPS开启时触发
*/
public void onProviderEnabled(String provider) {
Location location=lm.getLastKnownLocation(provider);
updateView(location);
}
/**
* GPS禁用时触发
*/
public void onProviderDisabled(String provider) {
updateView(null);
}
};