private Location getLastKnownLocation() {
List<String> providers = mLocationManager.getProviders(true);
Location bestLocation = null;
for (String provider : providers) {
Location location = mLocationManager.getLastKnownLocation(provider);
ALog.d("last known location, provider: %s, location: %s", provider, location);
if (location== null) {
continue;
}
if (bestLocation == null
|| location.getAccuracy() < bestLocation.getAccuracy()) {
ALog.d("found best last known location: %s", location);
bestLocation = location;
}
}
if (bestLocation == null) {
return null;
}
return bestLocation;
}
Android GPS Location null
最新推荐文章于 2021-12-07 14:10:30 发布
本文介绍了一种通过遍历可用的位置提供商来获取最准确的最后已知位置的方法。该方法使用了LocationManager服务来获取不同提供商的位置信息,并通过比较每个位置的准确性来选择最佳位置。
1万+

被折叠的 条评论
为什么被折叠?



