1

I am trying to use this technique in iOS7 to get a location every x seconds - Periodic iOS background location updates.

In my didUpdateLocations:

- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{
    [self.locationManager setDesiredAccuracy:kCLLocationAccuracyKilometer];
    [self.locationManager setDistanceFilter:9999];
}

When i run this, i seem to get a loop. setDesiredAccuracy: - i think this forces an update itself, on change. This is why I am getting a loop, would this be right? When I comment these out, it acts like I expect it too. Is there anyway to stop it get location when i set these?

4

1 回答 1

0

听起来你应该在你调用“”的频率上设置某种时间/日期戳setDesiredAccuracy。如果你调用它一次,请不要在一段时间内再次调用它。

就像是:

- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{
    NSTimeInterval secondsSinceLastResetOfAccuracy = [lastResetTime timeIntervalSinceNow];
    if(secondsSinceLastResetOfAccuracy > 60 * 60) // one hour
    {    
        [self.locationManager setDesiredAccuracy:kCLLocationAccuracyKilometer];
        [self.locationManager setDistanceFilter:9999];
        lastResetTime = [NSDate date]; // new "time stamp"
    }
}
于 2013-11-03T13:45:51.903 回答