Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CLLocation distanceFromLocation (in Swift?)

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! :-)

like image 745
Proteus Avatar asked Aug 12 '14 18:08

Proteus


2 Answers

let distance = fromLocation.distanceFromLocation(toLocation)

New syntax:

let distance = aLocation.distance(from: anotherLocation)
like image 143
Mundi Avatar answered Oct 25 '22 23:10

Mundi


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:

like image 21
Garrett O'Grady Avatar answered Oct 25 '22 21:10

Garrett O'Grady