功能" didUpdateToLocation"被召唤没有变化

时间:2012-10-07 20:38:12

标签: iphone ios location mkmapview cllocationmanager

我用这种方式初始化locationManager:

if (!self.locManager) 
{
    self.locManager = [[CLLocationManager alloc] init];
    self.locManager.delegate = self;
    [locManager startMonitoringSignificantLocationChanges];
}

我的设备没有移动,但仍然是#UuateToLocation"每次都被召唤。 可能有什么问题? 感谢

2 个答案:

答案 0 :(得分:3)

didUpdateToLocation可能由于多种原因而更新,处理此问题的一个好策略是根据时间戳逐步过滤结果,然后是所需的准确度。

Apple在LocateMe sample app中提供了一个很好的例子:

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
    // test the age of the location measurement to determine if the measurement is cached
    // in most cases you will not want to rely on cached measurements
    NSTimeInterval locationAge = -[newLocation.timestamp timeIntervalSinceNow];
    if (locationAge > 5.0) return;

    // test that the horizontal accuracy does not indicate an invalid measurement
    if (newLocation.horizontalAccuracy < 0) return;

    // test the measurement to see if it is more accurate than the previous measurement
    if (self.bestEffortAtLocation == nil || self.bestEffortAtLocation.horizontalAccuracy > newLocation.horizontalAccuracy)
    {
        // store the location as the "best effort"
        self.bestEffortAtLocation = newLocation;

        // test the measurement to see if it meets the desired accuracy
        //
        // IMPORTANT!!! kCLLocationAccuracyBest should not be used for comparison with location coordinate or altitidue 
        // accuracy because it is a negative value. Instead, compare against some predetermined "real" measure of 
        // acceptable accuracy, or depend on the timeout to stop updating. This sample depends on the timeout.
        //
        if (newLocation.horizontalAccuracy <= locationManager.desiredAccuracy) {
            // we have a measurement that meets our requirements, so we can stop updating the location
            // 
            // IMPORTANT!!! Minimize power usage by stopping the location manager as soon as possible.
            //
            [self stopUpdatingLocation:NSLocalizedString(@"Acquired Location", @"Acquired Location")];
        }
    }
}

答案 1 :(得分:0)

您检查位置差异吗?当精度,标题或速度等其他属性发生变化时,CoreLocation也会调用回调

startMonitoringSignificantLocationChanges应该给你一个初步修复,之后你会得到“重大改变”的回调(小区改变等)。