【发布时间】:2014-11-11 09:03:56
【问题描述】:
我正在努力通过 GPS 获取当前位置。但 GPS 总是给我最后保存的位置! 可能是因为这条线!我正在寻找更好的解决方案!
位置管理器 .getLastKnownLocation(LocationManager.GPS_PROVIDER);
这里是示例代码
if (isGPSEnabled) {
if (location == null) {
locationManager.requestLocationUpdates(
LocationManager.GPS_PROVIDER,
MIN_TIME_BW_UPDATES,
MIN_DISTANCE_CHANGE_FOR_UPDATES, this);
Log.d("GPS Enabled", "GPS Enabled");
if (locationManager != null) {
location = locationManager
.getLastKnownLocation(LocationManager.GPS_PROVIDER);
if (location != null) {
latitude = location.getLatitude();
longitude = location.getLongitude();
}
}
}
}
提前致谢!
【问题讨论】:
-
是的,因为您使用的是返回最后一个已知位置的 getLastKnownLocation
-
Pramod,要从 LocationManager 获取位置,只有 'locationManager.getLastKnownLocation()' 存在。 Andi,您可以使用“LocationManager.NETWORK_PROVIDER”代替“LocationManager.GPS_PROVIDER”。
-
@NikitaShah 我也试过 LocationManager.NETWORK_PROVIDER ......但这也没有用。