How to wait until location is completely found? (Core Location)
- by sudo rm -rf
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!