【发布时间】:2014-07-17 09:35:30
【问题描述】:
我不明白为什么 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 将无法工作。因此您还需要在这种情况下使用 NETWORK_PROVIDER 进行检查
-
@Biraj 我给了 NETWORK_PROVIDER 它仍然给出 null 直到某个时间之后。在继续之前如何确保不为空值
标签: android geolocation location latitude-longitude