Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android GPS Location Speed Unreliable

Writing a GPS logging application~

I'm finding the values returned by the getSpeed() method on Locations reported by LocationManager are massively unreliable. I'm using LocationManager.GPS_PROVIDER, filtering the Locations provided through onLocationChanged for best accuracy. Even at single digit accuracy levels the speed returned is generally ridiculously high. We're talking up to 200 mp/h (yes I know it's logged in metres/sec) when the phone is stationary.

I'm testing the same code base on two different model Android phones, running two different OS versions, and seeing the same issues so I expect this is a code issue.

What am I missing? I've tried averaging locations over a window of time, to no avail. Am I going to have to work out my own speed values based on distance travelled / time? This would be disappointing.

As you will see, I'm not doing anything special - a little filtering for accuracy, even after this both AverageSpeed and _bestLocation.getSpeed() are regularly unfeasibly high, even when accuracy of the location is good.

public void onLocationChanged(Location location) {
    if (location.getAccuracy() < 25f) {
        _recentLocations.add(location);

        if (_bestLocation == null || location.getAccuracy() <= _bestLocation.getAccuracy())
            _bestLocation = location;
    }

    if ((_bestLocation != null && _bestLocation.getAccuracy() < 10f && _recentLocations.size() >= 10)
            || _recentLocations.size() >= 25)
    {
        int Count = 0;
            float TotalSpeed = 0f;
            float AverageSpeed = 0f;
            for (int i = 0; i<_recentLocations.size(); i++) {
                if (_recentLocations.get(i).hasSpeed()) {
                    Count++;
                    TotalSpeed += _recentLocations.get(i).getSpeed();
                }
            }

        if (Count > 0)
                AverageSpeed = TotalSpeed / Count;
        }
}
like image 258
Dan Wray Avatar asked Jul 27 '12 10:07

Dan Wray


1 Answers

I have worked on GPS hardware for more than 7 years now. The accuracy reading is also not 100% accurate. Manufacturers state accuracy along with the system used for measuring it. CEP, RMS, 2DRMS, and R95 are some of the systems. Read this article for more information: http://en.wikipedia.org/wiki/Circular_error_probable

The accuracy figure does not include outliers. For example, if stated accuracy 5 meters then readings taken in good signal conditions will have maximum error of 5 meters, 95% of the time. Nothing can be said about the remaining 5% readings or about readings taken in bad signal contions. Protection against these outliers is the special sauce that makes a good location based app stand out from the rest.

Some things you can do are:

  1. Filter out insanely high speeds. Make use of altitude as hint for being in a airplane.
  2. Correlate information from motion sensors and see if they agree with GPS. Motion sensor signatures will be very different in steady state and in motion.
  3. The typical size of a GSM/3G cell is under a kilometer in urban areas and 5-10 kilometers in sparsely populated areas. If the vehicle is moving at high speed for some time and the cell tower information is still the same, you know something is wrong.
  4. Does the GPS fix read north one moment and south the next that too at a high speed? If yes, it is most likely a GPS error.
  5. Check the number of Satellites used in GPS calculation. 12 is outstanding, 9 is healthy, 5 or less is poor, 4 is bare minimum for lat,lon + altitude calculation, 3 is bare minimum for lat,lon calculation. Anything less than 3 is not a valid reading. You can be much more confident about the validity of data if number of satellites is high.
like image 59
Dojo Avatar answered Sep 27 '22 20:09

Dojo