Question

I'm getting strange readings when using CLLocationManager. The Lat/Long reported are spot on, but the distance traveled is WAY off. I've implemented the following delegate method as so:

.h:
    CLLocationManager *mLocationManager;
    CLLocation *mStartDistance;

And

.m:
    - (void) locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation
    fromLocation:(CLLocation *)oldLocation
    {
        NSLog(@"%g", newLocation.coordinate.latitude);
        NSLog(@"%g", newLocation.coordinate.longitude);
        NSLog(@"%g", newLocation.altitude);
        NSLog(@"%g", newLocation.verticalAccuracy);

    if (mStartDistance == nil)
    { mStartDistance = newLocation; }

    CLLocationDistance dist = [newLocation getDistanceFrom:mStartDistance];
    NSLog(@"%gm", dist);
}

And when I run this on my device I get the following (lat/long masked to protect the guilty heh):

] xx.xxxx
] -yy.yyyy
] 0
] -1
] 0m

] xx.xxxx
] -yy.yyyy
] 0
] -1
] 0m

] xx.xxxx
] -yy.yyyy
] 0
] -1
] 376.133m <-- wat?

I don't understand why its saying I've moved +376m..that's like +1200ft!

Was it helpful?

Solution

If you also log your newLocation.horizontalAccuracy, you'll probably see that for the first two updates it's over 400m. It's not using GPS (you're inside and it's giving you -1 for the altitude's vertical accuracy), and the cell phone triangulation can be pretty bad initially. Sometimes my initial location is only accurate to 10 miles, but it still puts down its best guess. Once it gets a better lock, that point can move pretty far quite fast.

Part of the trickiness in using CoreLocation is determining your own heuristic for accepting or rejecting an update. Some things to consider are the horizontal accuracy, the time spent updating, and the number of previous updates you've received. I've seen quite a few schemes have been discussed on this site previously.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top