IOS Location Update with NSTimer [duplicate]

左心房为你撑大大i 提交于 2019-12-25 02:47:36

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!