I have this code to wait for some time to get high accurate data:
-(void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation{
if((newLocation.horizontalAccuracy < 150 && newLocation.horizontalAccuracy > 0 /* valid */ && abs(howRecent) < 15.0 /*If it's a relatively recent event less than 15 seconds */))
}
the issue in other part of my application I need to wait for this method to come back, so i used:
[NSThread sleepForTimeInterval:5]; // wait 5 seconds
Is this a good practice, or there is a better way to wait for another task execution.
There is already a sample project provided by Apple that demonstrates this exact scenario.
The project is called LocateMe
and can be found here.
You can find the relevant methods in GetLocationViewController.m
.
In a few words, the logic behind it is to discard any cached values and accumulate location readings until the horizontalAccuracy
meets the desiredAccuracy
requirements. I hope that this will get you on the right track.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With