How to wait until location is completely found? (Core Location)

Posted by sudo rm -rf on Stack Overflow See other posts from Stack Overflow or by sudo rm -rf
Published on 2010-12-27T16:25:10Z Indexed on 2010/12/27 17:54 UTC
Read the original article Hit count: 255

Hello.

I have a problem within my app. I'm trying to find the user's location to the best preciseness in order to determine their zip-code. Currently I have a button that, when pressed, starts a method named locateMe.

-(IBAction)locateMe; {
self.locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
[locationManager startUpdatingLocation];

Then I've implemented didUpdateToLocation:

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

       NSLog(@"Found location! %f,%f",newLocation.coordinate.latitude,newLocation.coordinate.longitude);
 }

I had previously done much more complicated stuff in didUpdateToLocation but as I tested some things I realized that the first location it found was not precise in the least. So, I put the NSLog call in there and it gave me an output similar to below...

Found location! 39.594093,-98.614834
Found location! 39.601372,-98.592171
Found location! 39.601372,-98.592171
Found location! 39.611444,-98.538196
Found location! 39.611444,-98.538196

As you can see, it first gives me a value which is not correct, which was causing problems within my app because it wasn't giving the correct location.

So, here's my question. Is there any way I can wait for the location manager to finish finding the most precise location?

Thanks in advance!

EDIT: I'm wanting something like this:

if (newLocation.horizontalAccuracy <= locationManager.desiredAccuracy) {
}

But it never gets called!

© Stack Overflow or respective owner

Related posts about iphone

Related posts about objective-c