这是开发人员网站为获得更好的修复而提供的代码段。我对此有疑问。在此实现中,函数检查它是否显着更新,然后它在最开始时返回true。但是,如果较新的修复程序来自网络提供商并且准确性较低,该怎么办?它仍然返回true,但情况并非如此。这是一个错误还是我的理解错了?
链接:http://developer.android.com/guide/topics/location/obtaining-user-location.html
protected boolean isBetterLocation(Location location, Location currentBestLocation) {
if (currentBestLocation == null) {
// A new location is always better than no location
return true;
}
// Check whether the new location fix is newer or older
long timeDelta = location.getTime() - currentBestLocation.getTime();
boolean isSignificantlyNewer = timeDelta > TWO_MINUTES;
boolean isSignificantlyOlder = timeDelta < -TWO_MINUTES;
boolean isNewer = timeDelta > 0;
// If it's been more than two minutes since the current location, use the new location
// because the user has likely moved
if (isSignificantlyNewer) {
return true;
// If the new location is more than two minutes older, it must be worse
} else if (isSignificantlyOlder) {
return false;
}
// Check whether the new location fix is more or less accurate
int accuracyDelta = (int) (location.getAccuracy() - currentBestLocation.getAccuracy());
boolean isLessAccurate = accuracyDelta > 0;
boolean isMoreAccurate = accuracyDelta < 0;
boolean isSignificantlyLessAccurate = accuracyDelta > 200;
// Check if the old and new location are from the same provider
boolean isFromSameProvider = isSameProvider(location.getProvider(),
currentBestLocation.getProvider());
// Determine location quality using a combination of timeliness and accuracy
if (isMoreAccurate) {
return true;
} else if (isNewer && !isLessAccurate) {
return true;
} else if (isNewer && !isSignificantlyLessAccurate && isFromSameProvider) {
return true;
}
return false;
}
答案 0 :(得分:0)
显着更新意味着位置已经发生了很大变化,因此即使网络位置修复也比旧的gps位置修复更精确。所以是的,这是有道理的。
尽管如此,我认为你的想法是优先考虑最好的位置来源是好的,你应该实现它,并且可能从两个不同的来源维护两个不同的修复。
提供一个你受到启发的教程的链接会很不错。