【问题标题】:Core Location does't update the significant location changes核心位置不会更新重大的位置变化
【发布时间】:2013-03-22 04:53:08
【问题描述】:

在我的应用程序(部署目标 5.1)中,我正在使用 CoreLocation 设置提醒功能,它基本上会在设备更新其当前位置时搜索附近的项目(附加位置)。

这个功能在这个阶段不是很稳定,有时无论设备处于活动、挂起和终止状态,它都根本不起作用。我意识到委托方法locationManager:didUpdateToLocation:fromLocation: 没有被调用。

有没有人可以指点我一个方向,让这个东西正常工作?

这是我对 CLLocationManager 的设置

sharedLocationManager = [[CLLocationManager alloc]init];
[ESLocationManager defaultManager].delegate = someDelegateClassInstance;
[[ESLocationManager defaultManager] setDesiredAccuracy:kCLLocationAccuracyHundredMeters];
[[ESLocationManager defaultManager] startMonitoringSignificantLocationChanges];

以及委托回调的实现

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {

    // If it's a relatively recent event, turn off updates to save power
    NSDate* eventDate = newLocation.timestamp;
    NSTimeInterval howRecent = [eventDate timeIntervalSinceNow];
    if (abs(howRecent) < 20.0) {
        // If the event is recent,find nearby items.
        NSLog(@"latitude %+.6f, longitude %+.6f\n",
              newLocation.coordinate.latitude,
              newLocation.coordinate.longitude);

        //reload nearby list
        NSArray *nearbyItems = [self nearbyItemsForLocation:newLocation];
        if (nearbyItems && nearbyItems.count ) {
            UIApplicationState appState = [[UIApplication sharedApplication] applicationState];
            if (appState != UIApplicationStateActive) {
                [[UIApplication sharedApplication] presentLocalNotificationNow:[self localNotificationForItems:nearbyItems]];
            }
        }
    }

}

【问题讨论】:

  • 你怎么知道它不起作用?你如何测试它?另请注意,重要的位置更改服务不使用所需的准确度属性。只有当设备连接到不同的手机信号塔时,您才会获得新的位置。
  • 我在模拟器上使用 gpx 文件对其进行了测试,它在 iPhone 6.1 上运行良好,但在 iPhone 5.1 上效果不佳,通过使用位置,我可以看到列表已更新并且我能够接收设备处于非活动状态或终止时的通知。但是,当我在实际设备上对其进行测试时,它根本无法正常工作。我怀疑问题是由于位置更新在很大程度上取决于设备上附近的手机信号塔。 -_-

标签: ios core-location


【解决方案1】:

与本次论坛类似的区域监控原因

https://devforums.apple.com/message/251046#251046

希望对你有帮助

【讨论】:

    猜你喜欢
    • 2013-10-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多