I wrote an app to collect data via MotionManager, the scenario is an iPhone located inside a vehicle. I need to collection some location-related data as well (latitude, longitude and speed). I use a Timer to collect every 150ms the MotionManager data and at the same time I store the last location update. While the motion data is collected and the values make sense, I noticed that location data is updated only every second or so, despite the settings I used for LocationManager. Below my code:
locationManager = CLLocationManager()
locationManager.delegate = self
locationManager.desiredAccuracy = kCLLocationAccuracyBest
locationManager.distanceFilter = kCLDistanceFilterNone
motionManager = CMMotionManager()
motionManager.deviceMotionUpdateInterval = 1 / 30
locationManager.startUpdatingLocation()
motionManager.startDeviceMotionUpdates(using: .xArbitraryCorrectedZVertical)
timer = Timer.scheduledTimer(timeInterval: 0.15, target: self, selector: #selector(update), userInfo: nil, repeats: true)
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
locationLock.lock()
if let location = locations.last {
lastLocation = location
}
locationLock.unlock()
}
@objc func update() {
// function collecting the MotionManager data
locationLock.lock()
// do something with lastLocation.coordinate.latitude
// do something with lastLocation.coordinate.longitude
locationLock.unlock()
}
As the vehicle drives at least as fast as 50kmh/35mph, I would expect a new location value every 100-150ms. What am I missing?
Thanks