2011-09-12 71 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