甚至PRIORITY_HIGH_ACCURACY也提供了非常低精度的位置更新 [英] Even PRIORITY_HIGH_ACCURACY gives very low accuracy location updates
问题描述
我正在使用FusedLocationAPI获取高精度的位置更新(更新间隔为2秒,最快间隔为5秒)。在大多数情况下,它都能正常工作。但是,有时它可以提供大约1200m的精度。
I'm using FusedLocationAPI to get high accuracy location updates (with 2 second update interval and 5 second fastest interval). It works fine most of the times. But, sometimes it gives accuracy like 1200m.
我知道一开始它可能会发生。但是,我遇到的问题是,我得到了一段时间(大约20m精度)的公平更新,然后突然切换到了大约1200m精度。
I understand that in the beginning it can happen. But, the problem I'm having is, I get fair (~20m accuracy) updates for a while and then suddenly switches to ~1200m accuracy.
这怎么可能发生
推荐答案
有时会发生。此外,错误的定位信息可能会连续5分钟到达。
为了尝试过滤此类坐标,我使用了位置中描述的方法策略文章(请参见保持当前最佳估算值)。
Sometimes it happens. Moreover, erroneous location fixes can arrive for 5 minutes in a row. To try to filter such coordinates, I used the method described in Location Strategies article (see section Maintaining a current best Estimate).
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 Location API,但是可以使用。我只是对其进行了一些更正,因为所有修复程序都具有相同的提供程序。它使我可以过滤掉大约30%的错误定位信息。
It was designed for the use with a standard Android Location API, but it works. I just made a few corrections to it, because all fixes have the same provider. It allows me to filter about 30% of "bad" location fixes.
这篇关于甚至PRIORITY_HIGH_ACCURACY也提供了非常低精度的位置更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!