views:

260

answers:

1

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!

+2  A: 

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.

Matt B.
Good call, its actually 811m. Yeah, I'm just playing around with it. Cool, thanks Matt B.
Mr-sk
How is the Lat/Long spot on, but the hor/ver accuracy are so far off?
Mr-sk
Are you saying that you're getting good results with a high uncertainty in the accuracy? It might just be getting lucky.
Matt B.
The part of CoreLocation that uses databases of cell towers and WiFi APs learns. Since you've been there before when it did finally get resolved, it'll come up in the same spot again. It's still not guaranteed to be there until the process completes, so the error estimate is large.
Andrew McGregor