【发布时间】:2010-10-27 06:23:08
【问题描述】:
朋友们,
我正在使用以下代码获取 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) {
}
}
}
任何帮助将不胜感激。
【问题讨论】:
标签: android