Even PRIORITY_HIGH_ACCURACY gives very low accuracy location updates

不羁岁月 提交于 2020-01-04 05:39:10

问题


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.

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.

How can this happen in Fused API?


回答1:


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);
}

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.




回答2:


Distance measurement on raw GPS data will always be noisy, because the underlying data is often inaccurate. These jumps are due to inaccurate location measurements. To achieve, accurate distance measurements, you can need to filter the noise in the data.

Some useful filtering techniques that you can explore are:

  1. Smoothening location data using Kalman filters - see tutorial
  2. Snapping to road with Google maps snap-to-roads API, or OSRM match service.

If you are looking for an end-to-end solution that gives accurate location data and distance measurements, you can also try the HyperTrack SDK for Android or iOS. You can read about how they filter locations to improve accuracy on their blog.



来源:https://stackoverflow.com/questions/46193445/even-priority-high-accuracy-gives-very-low-accuracy-location-updates

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!