Tuesday, July 19, 2016

CLLocationDistance - Distance between two locations/coordinates

The following code finds out the distance between two coordinates. It is written with Xcode 7.3.1 playground. The distance is in meters.

import MapKit

let location1 = CLLocation(latitude: 24.953232, longitude: 121.225353)
let location2 = CLLocation(latitude: 24.9511, longitude: 121.2358)

let distance : CLLocationDistance = location1.distanceFromLocation(location2)

print("distance = \(distance) m")

where CLLocationDistance is the same as Double:

typealias CLLocationDistance = Double

No comments:

Post a Comment