때때로 발생합니다. 더욱이, 잘못된 위치 수정은 5 분 동안 계속 될 수 있습니다. 이러한 좌표를 필터링하려고 시도 했으므로 Location Strategies 문서 (최대 유지 보수 섹션 참조)에 설명 된 방법을 사용했습니다.
private static final int TWO_MINUTES = 1000 * 60 * 2;
/** Determines whether one Location reading is better than the current Location fix
* @param location The new Location that you want to evaluate
* @param currentBestLocation The current Location fix, to which you want to compare the new one
*/
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;
}
/** Checks whether two providers are the same */
private boolean isSameProvider(String provider1, String provider2) {
if (provider1 == null) {
return provider2 == null;
}
return provider1.equals(provider2);
}
표준 Android 위치 API와 함께 사용하도록 설계되었지만 작동합니다. 모든 수정 프로그램이 동일한 공급자를 가지고 있기 때문에 방금 수정했습니다. 그것은 "나쁜"위치 수정의 약 30 %를 걸러 내게합니다.
감사합니다. @fishbone. 하지만 실제로 원하는 것은 거리를 추적해야하므로 사용자의 가장 좋은 위치를 지속적으로 추적하는 것입니다. 가장 좋은 수정 프로그램을 유지하는 것은 그 시나리오에서 실제로 도움이되지 않습니다. 나는이 경우 거리계를 추적하기 위해 만보계로 바꾼다. 그럼에도 불구하고이 거대한 부정확성이 끝날 때까지 계속된다면 사용자의 마지막 위치가 무엇인지 알 수 없습니다. 특히 언급 한대로 몇 분 동안 계속 발생하는 경우. – wgihan