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.
mutatron
source share