iPhone CLLocationManager updates every 0.5 seconds

僤鯓⒐⒋嵵緔 提交于 2019-11-27 08:12:29

问题


For an app that does lots of calculation from the GPS, I need to get the latitude/longitude and speed every 0.5 second to be very accurate and avoid delay.

I am using:

  • [locationManager setDesiredAccuracy:kCLLocationAccuracyBestForNavigation];
  • - locationManager:didUpdateToLocation:fromLocation: function to store the value in 3 variables: newLatitude, newLongitude and newSpeed
  • An NSTimer object that call a function every 0.5 second.

See below a graph generated by Excel representing the latitude values during 18 seconds:

We can clearly see that we have location updates every second, and not every 0.5 second as wished. I do samples driving around my office, so my speeds vary between 0 and 65 MPH. So when I am driving 50MPH, I should get different values for lat/lon/speed from the iPhone every 0.5s right?

Please tell me how I can get those location updates every 0.5s if you know anything about the accuracy with the CLLocationManager object.

Thanks!


回答1:


You can't tell the location manager how often you want updates, but only respond when it chooses to give you updates. The timing of getting updates can't be counted on, it depends on the ease of finding WiFi signals and GPS signals.




回答2:


[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 //
}


来源:https://stackoverflow.com/questions/6104143/iphone-cllocationmanager-updates-every-0-5-seconds

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!