CLLocation distanceFromLocation (in Swift?)

别来无恙 提交于 2019-12-04 23:19:43

问题


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


回答1:


let distance = fromLocation.distanceFromLocation(toLocation)

New syntax:

let distance = aLocation.distance(from: anotherLocation)



回答2:


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:



来源:https://stackoverflow.com/questions/25271258/cllocation-distancefromlocation-in-swift

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!