CLLocation distanceFromLocation (在Swift中是什么?)

7

有人能帮我将下面的Objective-C语句转换成Swift吗?

CLLocationDistance distance = [fromLocation distanceFromLocation:toLocation];

我知道这一定很简单。我是iOS编程的新手,非常感谢您的帮助。
谢谢!:-)

1
使用 Playground 查明它。文档会向您展示此调用应该看起来像什么。 - Mundi
2
使用文档:func distanceFromLocation(location: CLLocation!) -> CLLocationDistance。在Xcode命令中单击CLLocationDistance以获取文档,然后搜索distanceFromLocation - zaph
2个回答

21
let distance = fromLocation.distanceFromLocation(toLocation)

新的语法:

let distance = aLocation.distance(from: anotherLocation)

1
现在已经弃用,请使用:let distance = location1.distance(from: location2) - josef

4

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接