Reputation: 289
I am capturing location data using CLLocationManager. I am less concerned about horizontal accuracy, but I want the speed to be as accurate as possible.
Anyone know if kCLLocationAccuracyThreeKilometers will be sufficient for my use case or do I have to use kCLLocationAccuracyBest to get the most accurate speed?
Thanks.
Upvotes: 0
Views: 1250
Reputation: 7892
I stuck in same issue in one of my Map Based application and i solved this way ( while traveling through Delhi Metro even i tested) and its working fine :
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
//Get Current Location
let location = locations.last! as CLLocation
let userLocation:CLLocation = locations[0] as CLLocation
// For getting speed
let speed = location.speed * 2.23694
lblSpeed.text = (location.speed<0) ? "-- \n mph" : String(format: "%d \n mph", Int(speed))
locationManager.startUpdatingHeading()
}
Accuracy is perfect in kCLLocationAccuracyBest
locationManager.desiredAccuracy = kCLLocationAccuracyBest
Feel free to provide your feedback after using this code . Hope it solve your issue . Keep Coding
Upvotes: 1
Reputation: 36277
AFAIK kCLLocationAccuracyThreeKilometers
works using cell towers (and doesn't use GPS), which doesn't give you every second's information (that's why it's good for battery), nor it uses core Motion. Without GPS or coreMotion any speed calculated won't be considered accurate
So to answer your question, no it won't give you an accurate speed, but just to be on the safe side, just jump into a car and start logging. (Though remember to turn location services off for all other apps, because sometimes other apps with better accuracy could increase your app's accuracy)
Upvotes: 1
Reputation: 6145
TLDR; kCLLocationAccuracyBest is the way to go.
For details, see https://stackoverflow.com/a/737968/190599
Upvotes: 0