views:

42

answers:

1

In the documentation it says that it gets an approximate location and then keeps updating with finer and finer precision. I have a button that does

[locManager startUpdatingLocation];

and then I implement

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation{
    [locManager stopUpdatingLocation];
}

and have it get directions somwhere. For some reason it's not updating locations when I drive somewhere. I would assume this is because it gets the "general location", and then doesn't have enough time to get an accurate reading. I also have

locManager.desiredAccuracy = kCLLocationAccuracyBestForNavigation;

Any thoughts? just need one time accurate readings. stumped. thanks.

A: 

Quick hack solution:

if (newLocation.horizontalAccuracy > 2*locManager.desiredAccuracy) {
  return;
}

A better solution might be to wait until accuracy stops improving, averaged over the last 5 updates or so.

tc.
so you're saying put a counter in the didUpdateLocation method and let it go 5 times before stopping? Might work. I'll try it.
marty
No, you compare the five horizontalAccuracy values and wait until it stops getting better. Sticking a counter should work too, provided you have good GPS reception (you might not, and then what should it do?), but 5 might be too little.
tc.