我不明白为什么 locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
返回位置 null。我给予了所有许可,但它的 reutning null
除外。
if (isGPSEnabled) {
if (location == null) {
locationManager.requestLocationUpdates(
LocationManager.GPS_PROVIDER,
MIN_TIME_BW_UPDATES,
MIN_DISTANCE_CHANGE_FOR_UPDATES, this);
Log.d("GPS", "GPS Enabled");
if (locationManager != null) {
location = locationManager
.getLastKnownLocation(LocationManager.GPS_PROVIDER);
if (location != null) {
latitude = location.getLatitude();
longitude = location.getLongitude();
}
}
}
}
最佳答案
我遇到了同样的问题。这是因为我的设备没有存储最后一个已知位置。我只是去谷歌地图并用 GPS 精确定位我的位置,然后为 getLastKnownLocation() 返回一个值
关于android - locationManager.getLastKnownLocation() 返回 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23906926/