【发布时间】:2016-07-31 01:07:25
【问题描述】:
我现在使用的方法非常不可靠。 在我的 Android 设备(不是模拟器)中,大多数时候返回的位置是 null 。虽然有时它确实有效。
public Location getLocation(String provider) {
if (locationManager.isProviderEnabled(provider)) {
locationManager.requestLocationUpdates(provider,
MIN_TIME_FOR_UPDATE, MIN_DISTANCE_FOR_UPDATE, this);
if (locationManager != null) {
location = locationManager.getLastKnownLocation(provider);
return location;
}
}
return null;
}
我知道在引入 API 23 之后,我还需要处理其他权限。 有没有可靠的方法来获取位置?
【问题讨论】:
标签: android gps location android-location