简体   繁体   English

Android:开发人员网站指南,以获得更好的位置修复

[英]Android: Developer site guidelines on getting better location fix

This is the code snippet that the developer site has provided for getting a better fix. 这是开发人员站点提供的代码片段,用于获得更好的修复程序。 I have a doubt in this. 我对此表示怀疑。 In this implementation, the function checks if it is significantly newer, then it returns true in the very beginning itself. 在此实现中,该函数检查其是否明显较新,然后从一开始就返回true。 But what if the newer fix is from the network provider and if it is less accurate. 但是,如果较新的修复程序来自网络提供商,并且准确性较差,该怎么办。 Still it returns true, which should not be the case. 它仍然返回true,事实并非如此。 Is this a bug or is my understanding wrong ? 这是错误还是我的理解错误?

Link: http://developer.android.com/guide/topics/location/obtaining-user-location.html 链接: 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;

} }

Significantly newer means location has changed a lot and thus even a network location fix is more precise than an older gps location fix. 显着更新意味着位置已发生很大变化,因此,即使是网络位置修复也比较早的gps位置修复更精确。 So yes that makes sense. 是的,这是有道理的。

Nevertheless, I think your idea to give priority to the finest location source is good, you should implement it and maybe maintain two different fixes from the two different sources. 但是,我认为将最好的位置信息源优先考虑的想法是好的,您应该实施它,并可能维护来自两个不同信息源的两个不同的修复程序。

It would have been nice to provide a link to the tutorial you got inspired by. 提供您从中获得启发的教程的链接将非常不错。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM