CLLocation distanceFromLocation (in Swift?)

9.9k Views Asked by At

Can somebody please help me convert the following Objective-C statement to Swift?

CLLocationDistance distance = [fromLocation distanceFromLocation:toLocation];

I know that it must be simple to do that. I am brand new to iOS programming and any help will be greatly appreciated.

Thank you! :-)

2

There are 2 best solutions below

1
On BEST ANSWER
let distance = fromLocation.distanceFromLocation(toLocation)

New syntax:

let distance = aLocation.distance(from: anotherLocation)
0
On
func distanceFromLocation(_ location: CLLocation!) -> CLLocationDistance

Returns the distance (in meters) from the receiver’s location to the specified location.

Read more here https://developer.apple.com/library/ios/documentation/CoreLocation/Reference/CLLocation_Class/index.html#//apple_ref/occ/instm/CLLocation/distanceFromLocation: