これは、開発者サイトがより良い修正を得るために提供しているコードスニペットです。私はこれに疑問がある。この実装では、関数はそれが大幅に新しいかどうかをチェックします。しかし、新しい修正がネットワークプロバイダからのものであって、それがあまり正確でない場合はどうでしょうか?まだそれは真実を返すが、そうであってはならない。これはバグですか、私の理解が間違っていますか?Android:開発者サイトのより良い位置情報の修正に関するガイドライン
リンク: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;
}
私はリンクを追加しました、私はそれが人が移動していない可能性があり、彼は低いネットワークカバレッジエリアであり、場所の修正がない可能性がありますので、正確である。それは意味をなさない? if(isSignificantlyNewer && isMoreAccurate)です。 –
私はそうは思わない。修正が大幅に新しい場合は、前回の修正を破棄する必要があることを意味します。人が移動していない場合は、もう一度gpsの位置情報を取得し直してください(以前にあった場合)。 – Snicolas
私はネットワークプロバイダーの修正を考慮に入れていました。低いカバレッジエリアでは、ネットワークプロバイダの修正のみが含まれているケースがあります。 –