使用NSTimer的iOS位置更新

使用NSTimer的iOS位置更新

本文介绍了使用NSTimer的iOS位置更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想每秒精确获取一次位置更新.对于我要创建的动画来说,此间隔很重要,以使其在地面上保持逼真的速度.我了解到[myLocationManager startUpdatingLocation]会自动轮询"didUpdateToLocations",但并不是每秒精确一次.

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.

是否可以使用NSTimer每秒精确地获取我的位置一次?

Is there any way to use NSTimer to get my location exactly once per second?

谢谢-jj

推荐答案

- (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
}

这篇关于使用NSTimer的iOS位置更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-24 20:13