CLLocation distanceFromLocation(在Swift?中)

时间:2014-08-12 18:11:20

标签: swift cllocation cllocationdistance

有人可以帮我将以下Objective-C语句转换为Swift吗?

CLLocationDistance distance = [fromLocation distanceFromLocation:toLocation];

我知道这样做一定很简单。我是iOS编程的新手,非常感谢任何帮助。

谢谢! : - )

2 个答案:

答案 0 :(得分:20)

let distance = fromLocation.distanceFromLocation(toLocation)

新语法:

let distance = aLocation.distance(from: anotherLocation)

答案 1 :(得分:4)

func distanceFromLocation(_ location: CLLocation!) -> CLLocationDistance

返回从接收者位置到指定位置的距离(以米为单位)。

在此处阅读更多https://developer.apple.com/library/ios/documentation/CoreLocation/Reference/CLLocation_Class/index.html#//apple_ref/occ/instm/CLLocation/distanceFromLocation