Location Manager更新频率,iphone



我有一个名为"myLocation"的CLLocation管理器。

myLocation = [[CLLocationManager alloc] init];
    myLocation.desiredAccuracy = kCLLocationAccuracyBestForNavigation ;
    myLocation.distanceFilter = 10 ;
    myLocation.delegate=self;

    locationEnabledBool = [CLLocationManager locationServicesEnabled];

    if (locationEnabledBool ==NO || ( [CLLocationManager  authorizationStatus] == kCLAuthorizationStatusDenied)) {
    //  LocationText.text = @"Location Service Disabled ";
        UIAlertView *locationAlert = [[UIAlertView alloc] initWithTitle:@"Location Service Disabled" 
                                                        message:@"To re-enable, please go to Settings and turn on Location Service for this app." 
                                                       delegate:nil 
                                              cancelButtonTitle:@"OK" 
                                              otherButtonTitles:nil];
        [locationAlert show];
        [locationAlert release];
    }
        [myLocation startUpdatingLocation];

和位置更新功能

- (void)locationManager:(CLLocationManager *)manager
    didUpdateToLocation:(CLLocation *)newLocation
           fromLocation:(CLLocation *)oldLocation
{
NSLog(@"old location is %f, %f ", oldLocation.coordinate.latitude, oldLocation.coordinate.longitude);
NSLog(@"new location is %f,%f",newLocation.coordinate.latitude, newLocation.coordinate.longitude );
}

是否有办法找到位置管理器更新的频率,如果它可以增加或减少?

您的位置更新仅在您调用方法[locationManager startUpdatingLocation]时开始。

您可以使用NSTimer控制更新的频率。每当需要位置更新时,定期调用startUpdatingLocation方法,然后立即调用stopUpdatingLocation方法。下次您将只在您在NSTimer中设置的间隔内获得位置更新。

为了检测最轻微的移动,您需要设置

myLocation.distanceFilter = kCLDistanceFilterNone ; 

但是,请记住,让位置管理器生成更新,即使是最轻微的移动可能会导致大量的电池使用。

最新更新