I am trying to build a GPS based odometer based on android.

Currently , I am calculating incremental distance changes very frequently ( < 5 meter movement). The distance calculation in android is using the WGS84 ellipsoid.

Currently on test runs, The gps calculations overshoots by 3 - 5% depending on route taken and duration of travel.

There are two problems I am facing :

  1. The distance calculation is not considering altitude.
  2. When the vehicle is stationary, gps starts injecting errors due to position changes which even though the device is stationary gps does calculation errors. This is the source of most of the error.

Details for error 2 :

Typically, when in a traffic signal / just plainly stopped on road. The android api tells me the new lat long pair when there is a displacement of minimum 5 meters. The problem is the api informs me of even the "drifted" lat long to be 5m away and hence I increment the odometer value which keeps accumulating errors because device did not move.Hence if the device is stationary it keeps accumulating this error.

An example "error" data when device is stationary

Device  Latitude    Longitude   Accuracy    Speed   Altitude    Heading
gps 13.0311466666667    77.5577383333333    41.5    1.9193991   894.7   295.77
gps 13.0311516666667    77.557795   38.8    0.99907583  892.8   294.88
gps 13.0311616666667    77.55784    38.4    0.5883275   886.4   294.88
gps 13.031175   77.5578866666667    37.5    0.74892086  886.1   294.88
gps 13.0311816666667    77.5579383333333    32.5    0.6552414   886 294.88
gps 13.0311516666667    77.557975   27.6    0   885.9   294.88
gps 13.0312016666667    77.5579733333333    32.4    0.7175228   885.9   294.88
gps 13.0312316666667    77.5579366666667    31.8    0.5610472   885.9   294.88
gps 13.031235   77.557885   30.4    0.9028228   885.9   294.88
gps 13.031245   77.5578366666667    30.5    0.81634945  885.8   294.88
gps 13.0312416666667    77.55779    27.9    0.5559  885.8   294.88
gps 13.0312233333333    77.5578433333333    23.9    0.43236667  886 294.88
gps 13.0312066666667    77.5578883333333    23.6    0.43905807  886.2   294.88
gps 13.03119    77.5579366666667    23.6    0.49258918  886.3   294.88
gps 13.0311666666667    77.5579983333334    24.9    0.77208334  886.7   294.88
gps 13.0311316666667    77.557945   22.4    0.3958214   887.8   241.89
gps 13.03113    77.5578416666667    25.2    0.24089 890.5   269.19
gps 13.0311133333333    77.5579 20.7    0.40663055  891.2   221.69
gps 13.0311116666667    77.5578516666667    21.9    0.47302973  891.3   251.03
gps 13.03104    77.55787    26.7    0.40199804  891.3   134.23
gps 13.0311033333333    77.5579333333333    23.6    0.5193547   891.6   332.92
gps 13.0310766666667    77.557985   19  0.38346806  893 118.18
gps 13.0311333333333    77.557945   27.9    0.3381725   896.9   287.31

Full data set is available here . It has > 5000 data points corresponding to a round trip from my home to office and back. From the start about ~800 data points are error beyond that the device starts moving.

Also adding raw nmea strings..

























Also, I am finding it very hard to visualize this data using excel, can anyone suggest better tools ( I use a MAC )

Can some one give me ideas to reduce the errors , perhaps a better algorithm to consider even altitude?

  • 1
    Is there something that limits your ability to incorporate altitude? Jul 16, 2012 at 12:29
  • @mhoran_psprep I needed an algorithm to incorporate altitude. ALso the altitude data fluctuates and is not very accurate.
    – srinathhs
    Jul 16, 2012 at 17:28
  • Because speed does not correlate at all well with differences in latitude and longitude, could you please explain what the speed means and how it is measured? There's a similar question about headings, but I also want to add that they are systematically wrong: they appear to have been computed from unprojected coordinates using Euclidean calculations. This alone will account for up to 2.5% of the error at latitudes of 13 degrees.
    – whuber
    Jul 16, 2012 at 18:43
  • The data is been calculated inside android internally and this is all I get from it. Android is handling the calculations. I sense it is better to calculate them myself using raw NMEA data ?
    – srinathhs
    Jul 16, 2012 at 18:53
  • I am beginning to think you are much better off with the raw NMEA data, because the Android calculations do not appear to make the most basic corrections for using geographic coordinates. Moreover, it will be more reliable to identify the noise in the raw data than to try to filter it out of data that have been processed according to some unknown algorithm.
    – whuber
    Jul 16, 2012 at 19:07

2 Answers 2


This is a fascinating problem where a little analysis can be most revealing.

First consider the effects of elevation. When a mapped unit distance is traversed, and the elevation changes by an amount dz (which for ground-based vehicles is always small compared to the map distance), then the actual distance traversed is very close to sqrt(1 + dz^2). (This would be perfectly accurate when the motion is made perfectly in a straight line. For actual motions over short distances that's usually a good approximation.) Because dz is presumed small, dz^2 is very small and dz^4 is incredibly small. This allows us to approximate the square root by 1 + dz^2/2, because the error made is proportional to dz^4.

Let's run some numbers to get a handle on the sizes of these errors. To make computation easy, choose our units of distance so that the vehicle traverses one unit between each GPS reading. Over the course of n readings, the mapped distance totals n*1 = n and neglects the additional distance from the elevation changes totaling about n * dz^2 / 2. How big might that be? Because dz determines the slope, the error depends on typical slopes. Approximately, a slope of t degrees translates into a value of dz of about t/60. The error relative to the mapped distance therefore equals (approximately)

(n * (t/60)^2 / 2)  /  n = t^2 / 7200.

For instance, for typical slopes of t = 10 degrees (fairly steep for most vehicles), the relative error equals 10^2 / 7200 = 1/72 = 1.5%.

Notice that this error should be thought of as negative: calculations from the mapped GPS coordinates would underestimate the true distance by this amount.

A similar analysis shows how one could correct a GPS reading based on an appropriate average of slopes encountered during a trip.

What about the other source of error, the measurement error in the GPS itself? This can be thought of as a random "drift" in the discrepancy between the observed GPS coordinates (X,Y) and the correct coordinates (x,y). The drift is a usually manifest as a gradual change in (X-x, Y-y) over time. It does indeed introduce some error, but it usually is not as great as one would think. In an answer at https://stats.stackexchange.com/a/2497, I report a typical 0.5% overestimate of total trip length. It would be difficult to produce an error that not only cancels out the negative error due to ignoring elevation, but also adds 3-5%.

These errors typically do not depend on duration of travel, but they do depend on the route. Normally, though, as a route becomes more tortuous, the GPS readings tend to replace "wiggles" with line segments, once more underestimating the distance. Again it is difficult to see how the GPS could be introducing a net 3-5% overestimate. Several possible alternative explanations are:

  1. The GPS may be subject to unusually erratic conditions, such as those that might be faced by a unit traveling deep within urban clutter.

  2. The distance believed to be correct might actually be incorrect. (For example, a car's tires can wear by 3% - 5% of their diameter during their usable lifetimes, resulting in a 3 - 5% increase in odometer readings. If the odometer is calibrated for a new fully inflated tire but the car is run on worn partly inflated tires to measure a route, it conceivably could overestimate the distance by 5% or more.)

  3. The "correct" distances may have been calculated on a map using a projection with substantial scale error.

  • Great answer !!.. however let me tell you why I am facing a overestimate.. Typically, when in a traffic signal / just plainly stopped on road.. the android api tells me the new lat long pair when there is a displacement of minimum 5 meters.. The problem is the api informs me of even the "drifted" lat long to be 5m away and hence I increment the odometer value which keeps accumulating errors because device did not move.. Hence if the device is stationary it keeps accumulating this error.. I can send you actual gps data for you to have a look..
    – srinathhs
    Jul 16, 2012 at 17:42
  • srinathhs, Posting the data would be welcome. (A short excerpt showing the structure and the first few and last few records for one dataset might suffice. You could also post a longer dataset elsewhere and link to it.) Your clarification is extremely helpful: could you please edit the question to include it? Given a reasonable understanding of the causes of the increases, I think it will be possible to identify a good procedure to smooth the data in a way that eliminates most of the unwanted "noise" and thereby reduces the bias in the distance estimates.
    – whuber
    Jul 16, 2012 at 17:49
  • I have edited the question with all info.
    – srinathhs
    Jul 16, 2012 at 18:11

It sounds like you need to a for structure, this will enable you to make the readings relevant if you have moved more than (Example 20m), if you have not moved more than 20m, it will save the gps data as a non point, and not add the errors to the odometer counter. Still this solution will not be 100% accurate. The more you stop, the more errors could be added. (Say you stop 5 times on a journey, the total Miliage may be out by 5*20m= 100m. Over a 20km trip that is an up to 0.5% error. Should be good enough seeing that most vehcle speedometers have more than 0.5% error.)

Cell phone Gps are not that accurate, in agriculture they have a temporary beacon (Usually on a tripod close to the field somewhere, so the exact position can be triangulated for an accurate positioning system.

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.