问题
I want to get location updates exactly once per second. This interval is important for an animation I want to create to keep true-to-life speed over the ground. I understand that [myLocationManager startUpdatingLocation] will automatically poll "didUpdateToLocations", but it is not quite exactly once per second.
Is there any way to use NSTimer to get my location exactly once per second?
Thank you -jj
回答1:
- (void)startUpdatingLocation
self.locationManager = [CLLocationManager new];
self.locationManager.desiredAccuracy = kCLLocationAccuracyBestForNavigation;
self.locationManager.delegate = self;
[self.locationManager startUpdatingLocation];
NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(updateLocation) userInfo:nil repeats:YES];
}
- (void)updateLocation {
CLLocation location = self.locationManager.location;
// do all the work here
}
#pragma mark - CLLocationManagerDelegate
- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations {
// do nothing here
}
来源:https://stackoverflow.com/questions/23698420/ios-location-update-with-nstimer