7

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

CLLocationDistance distance = [fromLocation distanceFromLocation:toLocation];

我知道这样做一定很简单。我是 iOS 编程的新手,任何帮助都将不胜感激。

谢谢!:-)

4

2 回答 2

21
let distance = fromLocation.distanceFromLocation(toLocation)

新语法:

let distance = aLocation.distance(from: anotherLocation)
于 2014-08-12T18:21:22.287 回答
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

于 2015-05-27T14:19:21.060 回答