views:

898

answers:

2

I have a program with a location manager set up like this:

self.locationManager = [[CLLocationManager alloc] init];
[locationManager startUpdatingLocation];
locationManager.delegate = self;
locationManager.distanceFilter = kCLDistanceFilterNone; 
locationManager.desiredAccuracy = kCLLocationAccuracyNearestTenMeters;

I need the accuracy to within ten meters, however, it takes a few calls of the didUpdateToLocation delegate method to find the location at that accuracy. How would I go about delaying the call of this method or just indicate when the desired accuracy is achieved in order to proceed with the program.

Right now it tries proceeds with the first location returned. Even the second location update is not as accurate as expected.

Thanks in advance!

+2  A: 

Since each delegate call includes an accuracy figure, simply return from the method until your desired accuracy is reached (warning: that may never happen).

You can't simply jump to a ten meter result - there's a reason why it's called "desired" accuracy and not mandatory accuracy. You have to give it time to calculate more exact positions.

Kendall Helmstetter Gelner
For some reason, when I check for this property ([newLocation horizontalAccuracy]), the LocationManager only updates twice and the newLocation is the same both times. Do you know of any reason for this?
Programasaurus
That's the best result it could find then. You are not always going to get results within ten meters - even when you have a GPS in the iPhone sometimes indoors it has to resort to cell tower triangulation.
Kendall Helmstetter Gelner
A: 

One strategy is to start a timer for a period long enough to get a fix (which will also be acceptable to the user)

+ (NSTimer *)scheduledTimerWithTimeInterval:(NSTimeInterval)seconds target:(id)target selector:(SEL)aSelector userInfo:(id)userInfo repeats:(BOOL)repeats

Start the location manager delivering updates. When the timer expires (or you get an acceptable accuracy) stop the updates and use that location.

It's probably the best you are going to get. You may want to give the user the option to try again for a location if it is still not accurate enough.

Kevin