Doe Doe - 1 year ago 151
Swift Question

Why iOS CLLocation shows incorrect values?

I'm trying to calculate distance between 2 coordinates. For this I do:

func setupLocationManager() {
if CLLocationManager.authorizationStatus() == .NotDetermined {

locationManager.delegate = self
locationManager.desiredAccuracy = kCLLocationAccuracyBest

func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
let latitude = locations.last?.coordinate.latitude
let longitude = locations.last?.coordinate.longitude

let myLocation = CLLocation(latitude: latitude!, longitude: longitude!)
let targetLocation = CLLocation(latitude: 41.4381022, longitude: 46.604910)

let distance = myLocation.distanceFromLocation(targetLocation)

I'm checking in Google Maps there are 13 km distance! But my app shows me 2-3 km!

How can I improve that?

Answer Source

Google maps gives you the route distance between two locations, CLLocation gives you the birds-eye distance between two locations.

From the documentation:

This method measures the distance between the two locations by tracing a line between them that follows the curvature of the Earth. The resulting arc is a smooth curve and does not take into account specific altitude changes between the two locations.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download