Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I've recently tackled this problem and discovered, <strong>by cleverly reading the documentation</strong> at long last, that CoreLocation runs in a separate thread, so you can start it up and then retrieve events as it updates. It's in the documentation under the rubric <a href="http://developer.apple.com/library/ios/#documentation/UserExperience/Conceptual/LocationAwarenessPG/CoreLocation/CoreLocation.html" rel="nofollow">"Getting the User's Location"</a>. So here's where you start updating:</p> <pre><code>- (void)startStandardUpdates { if (nil == locationManager) locationManager = [[CLLocationManager alloc] init]; locationManager.delegate = self; locationManager.desiredAccuracy = kCLLocationAccuracyBest; locationManager.distanceFilter = none; [locationManager startUpdatingLocation]; } </code></pre> <p>If you make the delegate "self", it will send events to the same class where the start method is defined, so then you just have to add the following to retrieve the events:</p> <pre><code>- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation { if (newLocation.horizontalAccuracy &lt; 30.0) { NSLog(@"latitude %+.6f, longitude %+.6f\n", newLocation.coordinate.latitude, newLocation.coordinate.longitude); [manager stopUpdatingLocation]; } } </code></pre> <p>This way it will keep receiving events and then turn off the GPS receiver to save energy. Of course it needs a time out and some way to store and accept the location with the best horizontal accuracy if it times out, but I haven't figured out how to do that yet.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload