2011-09-12 74 views
11

我有一个称为“myLocation”的CLLocation管理器。位置管理器更新频率,iphone

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); 
} 

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

+1

位置管理器中没有这样的选项....只要检测到位置更改,就会调用委托。但是你可以改变精确度......也就是说,它应该在每十米变化还是100米或1公里变化......等等。 – booleanBoy

+0

但是如果设备静止,位置更新也会发生。 – alekhine

+0

你的意思是即使设备静止,你也可以获得位置的坐标....? – booleanBoy

回答

21

只有当您调用方法[locationManager startUpdatingLocation]时,才会启动位置更新。

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

+0

感谢您的耐心帮助我。你的答案肯定有帮助。下次我会更清楚地问问题。 – alekhine

+0

不客气:) – booleanBoy

+0

@ amol-subhedar我需要你的帮忙...你能帮我吗? :) – booleanBoy

2

因为即使检测丝毫的动作,你需要设置

myLocation.distanceFilter = kCLDistanceFilterNone ; 

但是,请记住,让位置管理器生成的更新即使是最轻微的动作都可以在很多电池使用的结束。

+1

kCLDistanceFilterNone是默认的... – Jake