1

我以这种方式初始化 locationManager:

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

我的设备没有移动,并且每次仍然调用“didUpdateToLocation”。可能是什么问题?谢谢

4

2 回答 2

3

didUpdateToLocation由于多种原因可能会更新,处理此问题的一个好策略是根据时间戳逐渐过滤结果,然后要求准确性。

Apple 在LocateMe 示例应用程序中提供了一个很好的示例:

- (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")];
        }
    }
}
于 2012-10-11T21:28:21.347 回答
0

你检查位置差异吗?当其他属性(如准确性、航向或速度)发生变化时,CoreLocation 也会调用回调

startMonitoringSignificantLocationChanges应该给你一个初步的修复,然后你会得到“重大变化”的回调(蜂窝塔变化等)

于 2012-10-07T20:42:38.843 回答