如果设备的位置更改5或10米,如何获取通知?

时间:2017-04-09 17:24:40

标签: ios objective-c cllocationmanager cllocation

我正在开展一个项目,我需要存储设备的纬度和经度。但是当设备在其位置改变5或10米时,我需要存储它们。我用谷歌搜索了大约2天,但找不到任何帮助我的东西。所以我想出了intuit/LocationManager库。我可以通过这个库成功获得单一位置。但- subscribeToSignificantLocationChangesWithBlock:此方法内的区块只执行一次,而不管设备位置的更改次数

我已经使用真实设备模拟器对其进行了测试。在模拟器上,我手动更改了这样的位置:simulate location image

但我没有获得 重大更改 更新。

这是我到目前为止所做的:

- (void)startMonitoringSignificantLocationChanges
{
    __weak __typeof(self) weakSelf = self;
    INTULocationManager *locMgr = [INTULocationManager sharedInstance];
    self.locationRequestID = [locMgr subscribeToSignificantLocationChangesWithBlock:^(CLLocation *currentLocation, INTULocationAccuracy achievedAccuracy, INTULocationStatus status) {
        __typeof(weakSelf) strongSelf = weakSelf;

        _lastLocation = currentLocation;

        if (status == INTULocationStatusSuccess) {
            _significantChangeCount++;

            // A new updated location is available in currentLocation, and achievedAccuracy indicates how accurate this particular location is
            strongSelf.changedLatitude.text = [NSString stringWithFormat:@"%f", currentLocation.coordinate.latitude];
            strongSelf.changedLongitude.text = [NSString stringWithFormat:@"%f", currentLocation.coordinate.longitude];
            strongSelf.changedTime.text = [self getLocaleDateString:currentLocation.timestamp];
            if (_significantChangeCount > 0) {
                strongSelf.changedStatus.text = @"Significant change";
            } else {
                strongSelf.changedStatus.text = @"Monitor started";
            }
        }
        else {
            // An error occurred
            strongSelf.errorLabel.text = [strongSelf getLocationErrorDescription:status];
        }
    }];
}

任何帮助将不胜感激。或任何其他方式来完成这项任务??

1 个答案:

答案 0 :(得分:0)

5到10米的运动不算作重要的"位置变化:

  

只要设备从之前的通知移动500米或更长时间,应用就会收到通知。它不应该比每五分钟更频繁地预期通知。

source

如果您需要监控5-10米范围内的变化,则需要使用其他方法。