根据苹果的文件,重要的位置变化应该至少每15分钟更新一次。当我大幅移动时,我确实收到了更新,但当设备处于静止状态时,我却没有收到更新。你对更新有什么经验?他们至少每15分钟来一次吗?
如果GPS级别的精度对您的应用程序来说并不重要,并且不需要持续跟踪,您可以使用重大更改位置服务。正确使用重大更改位置服务至关重要,因为它至少每15分钟就会唤醒系统和应用程序,即使没有发生任何位置更改,它也会持续运行,直到停止为止。
发布于 2016-02-25 19:16:16
我有个天真的解决方案。您可以使用NSTimer强制CLLocationManger实例每15分钟更新一次当前位置,或者按您希望它定期更新的时间进行更新。
下面是我将使用的代码:
首先,调用此方法,在viewDidLoad或其他位置需要时开始更新您的位置。
- (void)startStandardUpdates
{
if (nil == locationManager){
locationManager = [[CLLocationManager alloc] init];
}
locationManager.delegate = self;
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
// 900 seconds is equal to 15 minutes
NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:900 target:self selector:@selector(updateUserLocation) userInfo:nil repeats:YES];
[timer fire];
}其次,实现updateUserLocation方法:
-(void)updateUserLocation{
[self.locationManager startUpdatingLocation];
}最后,对协议进行确认,然后实现位置做更新的方法。我们读取最新更新的结果,让位置管理器停止更新当前的位置,直到接下来的15分钟。
-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray<CLLocation *> *)locations{
CLLocation *userLocation = [locations objectAtIndex:0];
CLLocationCoordinate2D userLocationCoordinate = userLocation.coordinate;
/*
Do whatever you want to update by using the updated userLocationCoordinate.
*/
[manager stopUpdatingLocation];
}https://stackoverflow.com/questions/35482846
复制相似问题