朋友,
我正在使用以下代码来获取GPS位置
导致两个问题
1)当我的位置发生变化/我将手机从一个区域移动到另一个区域时我不会更新gps位置(纬度/经度)
2)获取gps位置后,我的手机gps启用如何禁用它?
double MyDeviceLatitude,MyDeviceLongitude;
public void GetGPSLocation()
{
LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
LocationListener myLocationListener = new CurrentLocationListener();
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 30, 30, myLocationListener);
Location currentLocation = locationManager.getLastKnownLocation("gps");
if(currentLocation != null)
{
MyDeviceLatitude = currentLocation.getLatitude();
MyDeviceLongitude = currentLocation.getLongitude();
}else
{
currentLocation = locationManager.getLastKnownLocation("network");
MyDeviceLatitude = currentLocation.getLatitude();
MyDeviceLongitude = currentLocation.getLongitude();
}
public class CurrentLocationListener implements LocationListener{
public void onLocationChanged(Location argLocation)
{
if (argLocation != null)
{
MyDeviceLatitude = argLocation.getLatitude();
MyDeviceLongitude = argLocation.getLongitude();
}
}
public void onProviderDisabled(String provider) {
}
public void onProviderEnabled(String provider) {
}
public void onStatusChanged(String provider, int status, Bundle arg2) {
}
}
}
任何帮助将不胜感激。
答案 0 :(得分:0)
UMMA请查看使用广播接收器的类似帖子,这似乎可以解决您的问题Android: How to get location information from intent bundle extras when using LocationManager.requestLocationUpdates()