簡體   English   中英

Android:開發人員網站指南,以獲得更好的位置修復

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

這是開發人員站點提供的代碼片段,用於獲得更好的修復程序。 我對此表示懷疑。 在此實現中,該函數檢查其是否明顯較新,然后從一開始就返回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;

}

顯着更新意味着位置已發生很大變化,因此,即使是網絡位置修復也比較早的gps位置修復更精確。 是的,這是有道理的。

但是,我認為將最好的位置信息源優先考慮的想法是好的,您應該實施它,並可能維護來自兩個不同信息源的兩個不同的修復程序。

提供您從中獲得啟發的教程的鏈接將非常不錯。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM