iPhone CLLocationManager每0.5秒更新一次

时间:2011-05-23 23:19:53

标签: iphone cllocationmanager

对于从GPS进行大量计算的应用程序,我需要每0.5秒获得纬度/经度和速度,以确保非常准确并避免延迟。

我正在使用:

  • [locationManager setDesiredAccuracy:kCLLocationAccuracyBestForNavigation];
  • - locationManager:didUpdateToLocation:fromLocation:函数将值存储在3个变量中:newLatitudenewLongitudenewSpeed
  • 每0.5秒调用一次函数的NSTimer对象。

参见下面Excel生成的图表,表示18秒内的纬度值:

Latitude values during 18 seconds

我们可以清楚地看到我们每秒都有位置更新,而不是每隔0.5秒就有所需。我在办公室里做样品,所以我的速度在0到65英里/小时之间。因此,当我驱动50MPH时,我应该每隔0.5秒从iPhone获得不同的lat / lon / speed值?

如果您对CLLocationManager对象的准确性一无所知,请告诉我如何每0.5秒获取一次这些位置更新。

谢谢!

2 个答案:

答案 0 :(得分:5)

您无法告诉位置管理员您希望更新的频率,但只有在选择为您提供更新时才会响应。获取更新的时间不能指望,这取决于寻找WiFi信号和GPS信号的难易程度。

答案 1 :(得分: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 //
}