即使没有命中distancefilter指定的距离,ios位置管理器也会触发

时间:2014-09-29 15:19:50

标签: ios location cllocationmanager

有人可以告诉我为什么我的距离过滤器设置为30米后每两步左右更新一次位置更新?

- (void)initLocationTrackingStandard 
{
    [self.locationManager setPausesLocationUpdatesAutomatically:YES];
    [self.locationManager setActivityType:CLActivityTypeOther];
    [self.locationManager setDistanceFilter:30.0];
    [self.locationManager setDesiredAccuracy:kCLLocationAccuracyNearestTenMeters];

    [self.locationManager startUpdatingLocation];
}


- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations 
{
    CLLocation* location = [locations lastObject];
    NSDate* eventDate = location.timestamp;
    NSTimeInterval howRecent = [eventDate timeIntervalSinceNow];

    if (abs(howRecent) < 5.0)
    {
        // Use location if it is within 5 seconds
        UILocalNotification *localNotification = [[UILocalNotification alloc] init];
        localNotification.alertBody = @"update location";
        localNotification.soundName = UILocalNotificationDefaultSoundName;

        [[UIApplication sharedApplication] presentLocalNotificationNow:localNotification];
    }
}

0 个答案:

没有答案