2011-05-23 212 views
2

對於從GPS進行大量計算的應用程序,我需要每0.5秒獲取一次經緯度和速度,以便非常準確並避免延遲。iPhone CLLocationManager每0.5秒更新一次

我使用:

  • [locationManager setDesiredAccuracy:kCLLocationAccuracyBestForNavigation];
  • - locationManager:didUpdateToLocation:fromLocation:函數值存儲在3個變量:newLatitudenewLongitudenewSpeed
  • 一個NSTimer對象調用一個函數每0.5秒。

期間18秒見Excel中表示緯度值生成的圖表如下:

Latitude values during 18 seconds

我們可以清楚地看到,我們的位置每秒更新,而不是每0.5秒的希望。我在我的辦公室駕駛樣品,所以我的速度在0到65 MPH之間變化。所以當我駕駛50MPH時,我應該每隔0.5秒從iPhone獲得不同的經度/緯度/速度值?

請告訴我如何通過CLLocationManager對象瞭解關於精度的任何信息,我如何才能每隔0.5s獲取一次位置更新。

謝謝!

+2

CoreLocation Services決定何時向您發送位置更新,您不能直接調用它並獲得立即值。 GPS三角測量非常昂貴,並且設備使用很多技巧來節省電池並提高準確度。 – rjstelling 2011-05-23 23:34:51

回答

5

您無法告訴位置管理者您希望更新的頻率,但只有在您選擇提供更新時纔會做出響應。獲取更新的時間不能計算在內,這取決於查找WiFi信號和GPS信號的難易程度。

+0

謝謝@nevan,這就是我的想法。我通常會每秒收到一次更新,至少它很棒。我只是想用0.5s來更加準確,但不幸的是,我不能決定這一點,只能等待代表接收更新。 – Dachmt 2011-05-23 23:52:47

0
[self.locationManager startUpdatingLocation]; 
NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self  selector:@selector(myTimerFunc) userInfo:nil repeats:YES]; 

- (void)myTimerFunc 
{ 
    CLLocation location = self.locationManager.location; 
    // do work here // 
} 

- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations 
{ 
    // do nothing here // 
}