Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to wait for until location Manager to get high accurate data

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.

like image 238
user836026 Avatar asked May 31 '12 12:05

user836026


1 Answers

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.

like image 136
Alladinian Avatar answered Oct 25 '22 00:10

Alladinian