CLLocation distanceFromLocation (in Swift?)
Asked Answered
D

2

7

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

Derogatory answered 12/8, 2014 at 18:11 Comment(2)
Use Playground to figure it out. The documentation shows you exactly what this call should look like.Headword
Use the documentation: func distanceFromLocation(location: CLLocation!) -> CLLocationDistance. In Xcode Command click on CLLocationDistance to get to the documentation and then search for distanceFromLocation.Woolgathering
H
21
let distance = fromLocation.distanceFromLocation(toLocation)

New syntax:

let distance = aLocation.distance(from: anotherLocation)
Headword answered 12/8, 2014 at 18:21 Comment(1)
now deprecated so use: let distance = location1.distance(from: location2)Jennettejenni
P
4
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:

Pix answered 27/5, 2015 at 14:19 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.