Mapkit and didUpdateToLocation - calculating distance accuracy on iOS

791 Views Asked by At

I've made an application calculating distance when walking / running for iPhone.

I've compared my application to other running application, and no one gives the same distance.

Nike GPS : 2.1 Km
Runtastic : 2.5 Km
My App : 2.9 Km

Here the routing to calculate distance :

- (void)locationManager:(CLLocationManager *)manager
    didUpdateToLocation:(CLLocation *)newLocation
           fromLocation:(CLLocation *)oldLocation

 {
 float distInMeter = [newLocation distanceFromLocation:oldLocation]; // which returns in    meters
 }

and I concatenate distInMeters to another variable.

Why is there a such difference between those applications ? Is there another way to calculate the distance more precisely ?

Thanks for your help.

3

There are 3 best solutions below

0
On

GPs positions must be filtered before calculating distances. you cannot simply sum up all distances between each location. your distance function is correct, but your filtering not. just visualize all points on the map (mkMapView), then you see that at low speeds gps creates zig-zag random error lines. from this visualisation you clearly should see why your distances are much greater.

1
On

Such difference can happen because of the way the location manager delivers user positions. Let's say you are walking in a certain direction and the GPS gives you a position totally off from that direction, but the next one is right on track again. If you take into account the one that was off, you are accounting for more distance than the user actually traveled. So you should filter out that one.

Same thing goes if the GPS gives you another position that is farther away than it should be. Let's say the user is jogging at 4 mph, so it would be impossible that the user suddenly started running at 100 mph, so you should filter out that one too.

Basically, you should filter out the ones that are very unlikely to happen, and that way you will get a more precise distance.

0
On

Those apps have been working with inaccurate GPS data for a long time and have created ways to smooth random jumps in the location. Your implementation isn't taking old data or spurious data into account.

You can try implementing a Ramer–Douglas–Peucker algorithm (here's one in Javascript) or reading some of these very complicated papers, or you could just discard old or very different GPS readings and wait until a more accurate reading comes in.