CoreLocation disadvantage

I have a program with a location manager configured as follows:

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

I need accuracy with an accuracy of ten meters, however, to determine the location with such accuracy, several calls to the didUpdateToLocation delegation method are required. How can I defer the call to this method or simply indicate when the desired accuracy will be achieved to continue the program.

Now he is trying to continue the first returned location. Even the second location update is not as accurate as expected.

Thanks in advance!

+6
objective-c iphone core-location gps location
source share
3 answers

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

You can’t just go to the ten-meter result - there is a reason why it is called the “desired” accuracy, and not the required accuracy. You must give him time to calculate more accurate positions.

+7
source share

I recently looked at this problem and found that , having skillfully read the documentation , finally that CoreLocation works in a separate thread, so you can run it and then receive events as it updates. This is in the documentation under the heading “Getting the user's location” . So, here where you start the update:

 - (void)startStandardUpdates { if (nil == locationManager) locationManager = [[CLLocationManager alloc] init]; locationManager.delegate = self; locationManager.desiredAccuracy = kCLLocationAccuracyBest; locationManager.distanceFilter = none; [locationManager startUpdatingLocation]; } 

If you make the delegate "I", it will send events to the same class as the start method, so you just need to add the following to retrieve the events:

 - (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation { if (newLocation.horizontalAccuracy < 30.0) { NSLog(@"latitude %+.6f, longitude %+.6f\n", newLocation.coordinate.latitude, newLocation.coordinate.longitude); [manager stopUpdatingLocation]; } } 

In this way, it will continue to receive events, and then turns off the GPS receiver to save power. Of course, he needs time and a way to save and accept the location with the best horizontal accuracy if it expires, but I still haven't figured out how to do this.

+4
source share

One strategy is to start the timer for a period sufficient to receive the 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 

Run the location manager, which delivers updates. When the timer expires (or you get acceptable accuracy), stop the updates and use this location.

This is probably the best you get. You might want to give the user the opportunity to retry for a location if it is still not accurate enough.

+2
source share

All Articles