位置管理器更新频率,iphone

ale*_*ine 11 iphone cllocationmanager

我有一个名为"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];
Run Code Online (Sandbox Code Playgroud)

和位置更新功能是

- (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 );
}
Run Code Online (Sandbox Code Playgroud)

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

Boo*_*Boy 21

只有在调用方法时才会启动位置更新[locationManager startUpdatingLocation].

您可以使用a控制更新的频率NSTimer.调用startUpdatingLocation时,你需要一个位置更新,然后立即拨打定期方法stopUpdatingLocation方法.下次您将仅以您在中设置的时间间隔获得位置更新NSTimer.

  • booleanBoy - 使用acclerometer来发现诸如此类的细微变化 (3认同)

小智 5

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

myLocation.distanceFilter = kCLDistanceFilterNone ; 
Run Code Online (Sandbox Code Playgroud)

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