問(wèn)題描述
我不明白為什么 locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
返回位置 null.我給予了所有許可,但它的 reutning null
除外.
i dont understand why locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
return the location null. I gave all permission but its 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();
}
}
}
}
推薦答案
我也遇到了同樣的問(wèn)題.這是因?yàn)槲业脑O(shè)備沒(méi)有存儲(chǔ)最后一個(gè)已知位置.我只是去谷歌地圖并用 GPS 精確定位我的位置,然后為 getLastKnownLocation() 返回一個(gè)值
I had this exact same problem. It was because my device was not storing a last known location. I simply went on to Google Maps and pinpointed my location with GPS, then a value was returned for getLastKnownLocation()
這篇關(guān)于locationManager.getLastKnownLocation() 返回 null的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!