15

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;
        }
}
6
  • Have you tried this in different places as well? In some places, you just won't get a GPS fix no matter what. Jul 27, 2012 at 10:26
  • I should have specified, I'm getting very acceptably accurate fixes - 5 - 10 metres typically. Places are as varied as possible- trips from office to customer sites and home etc.
    – Dan Wray
    Jul 27, 2012 at 10:30
  • @DanWray hai, have you fixed this problem, now i'm struggling with the same, could you help me with this?. Aug 4, 2014 at 9:35
  • @madhu the issue really did lie with my code. See the (very good) accepted answer and it should tell you pretty much all you need to know. You just cannot trust a single GPS fix, you have to filter and aggregate the data over a period of time to give your application a strong indication of location.
    – Dan Wray
    Aug 5, 2014 at 9:26
  • @DanWray, Thanks for your prompt comment, let me check with the accepted answer. Aug 5, 2014 at 12:30

4 Answers 4

31

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.
6
  • 3
    Helpful. I've been working with GPS applications for a long time too and the first indicator of accuracy I usually use is the satellite count. In Android's case I had overlooked that satellite count is available through the getExtras() method, and have been relying on the reported accuracy in metres for my confidence level. I'll take your comments into account and attempt to improve my code, thanks.
    – Dan Wray
    Jul 27, 2012 at 11:51
  • 2
    Very true. Android documentation provides also a very good description of how the locaiton providers work and how to filter unacurrate locations. developer.android.com/guide/topics/location/strategies.html
    – L. G.
    Dec 3, 2012 at 9:32
  • @Dojo Thank you for such wide answer. Can you, please, point me in right direction? I need to calculate distance for vehicle stand on low-level android devices with gps it usually 10-25km but with accuracy not less then 0.5-0.8 km for one such session. Will your precautions be enough for such case? Or I need to use more advanced filtering technics like Kalman Filtering(which I heard). Thanks in advance!
    – ar-g
    Jan 26, 2015 at 12:05
  • @Dojo I am using an iPhone to get the GPS values. The speed reported during the take is very less (1- 15 mph), but if I calculate the speed manually (straight line distance between two points / time), it comes out to be 250-350 mph. Does phone's gps fails at such high speeds and report inaccurate data ?
    – devdoe
    Aug 31, 2018 at 9:25
  • @nr5 Are you checking the validity of GPS messages before letting them into your calculations? One possibility is the GPS is signal is not good which causes the position to not update for a while so you get old position and then suddenly the device gets a valid fix and you get the current position. So to your algorithm, it would look like the position change happened in 1 second. For all such calculations, only use valid GPS fixes.
    – Dojo
    Sep 2, 2018 at 6:40
1

GPS devices are positional speedometers, based on how far the receiver has moved since the last measurement. Its speed calculations are not subject to the same sources of error as the vehicle's speedometer (wheel size, transmission/drive ratios). Instead, the GPS's positional accuracy, and therefore the accuracy of its calculated speed, is dependent on the satellite signal quality at the time. Speed calculations will be more accurate at higher speeds, when the ratio of positional error to positional change is lower.

From Wikipedia.

Probably you should try this in place where you have good signal strength.

4
  • Understood, and thanks for your comment. I've written this same application to run on Blackberry phones and similar on WinMo and WP7 and I've never had such issues with the speed versus GPS accuracy. As you can see from the code I will not accept a position with accuracy of <25m and ordinarily will see accuracy of <10m, especially when the phone is outside and moving (ie when I need the speed). At this level of accuracy I would expect to see speed values which are at least in the correct order of magnitude.
    – Dan Wray
    Jul 27, 2012 at 10:36
  • Am not aware of the differences between phones, but I had the same issue on iPhone when I tried different location. Places where GPS accuracy is in few meters, we got very good acuracy in speed but in places where it was 50meters accurate, we had very bad speed accuracy. And like the quote explains, it is completely based on location estimation, the speed is calculated by just previous location estimation and current location estimation and time difference.
    – codetiger
    Jul 27, 2012 at 10:51
  • Indeed, and therein lies my issue - open outdoor locations with strong fix accuracy are reporting stupid speeds. I'm going to try manually determining the speed by comparing successive Locations vs the time elapsed, however it feels like I'm reproducing work that should already have been done, and my hopes aren't high that I'll see a better result. Thanks for your input regardless.
    – Dan Wray
    Jul 27, 2012 at 10:59
  • When searching on the net you will find multiple seemingly reliable sites stating that gps speed is calculated by delta distance deviced by delta. Other seemingly reliable sites state that the doppler effect is used to calculate speed directly (and less error prone) from one gps fix without resorting to a previous fix. This makes total sense given the jumping of inacurate gps on stationary vehicles. I would think that the second answer is correct and doppler is used. But it might be dependent on the chipset capabilities? Can anyone elaborate? Jun 25, 2020 at 13:43
1

I am experiencing the same problem. I think GPS signal depends on a location, some location may give an exact output of location otherwise a 'not-so-reliable' result. In my case, I was located about 200 meters away from my actual location. How about you?

To add, GPS_PROVIDER does not work here in my area. NETWORK_PROVIDER does, and it's the one that give the 200 meters away result.

2
  • I'm fortunate to be able to use GPS_PROVIDER, however even with NETWORK_PROVIDER I've been able to see more accurate fixes than 200m. Have you tried watching your listener over a period of time and look for better accuracy? Somewhat similar to my code above. Of course network/wifi coverage will vary massively in different areas of the world so your experience could well differ somewhat to mine.
    – Dan Wray
    Jul 27, 2012 at 11:04
  • Yes, I tried getting the best provider, the best accuracy and also the best criteria, but when I use the GPS_PROVIDER, it does not return any location result.
    – JetPro
    Jul 29, 2012 at 8:16
0

It seemes that most people are assuming that speed information from GPS is based on comparing positions related to time diference. This method is not very good for determining speed, and is worse at lower speeds of travel.

GPS receivers can output speed measurement based on doppler shift from the sattelite measurements. Accuracy of the speed measurement based on doppler is MUCH better compare to speed measurements based on position/time calculations.

Google on gps speed doppler and You will find a lot to read.

One link is here: http://nujournal.net/HighAccuracySpeed.pdf

/Urban Holmdahl

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.