ios - 给定两组坐标,如何计算它们之间的距离?

标签 ios swift

假设我有两点:

var lat1 =  37.7833 
var lon1 = -122.4167
var lat2 =  39.4811 
var lon2 = -118.9558

如何最简单地计算它们之间的距离? (考虑到地球的曲率)

我调查了 this答案,但是 CCLocation 在 Swift 2.0 中没有初始化器

最佳答案

let coord1 = CLLocation(latitude: 37.7833, longitude: -122.4167)
let coord2 = CLLocation(latitude: 39.4811, longitude: -118.9558)
let distance = coord1.distance(from: coord2)

print("the distance between the two points is: \(distance) meters")

关于ios - 给定两组坐标,如何计算它们之间的距离?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35123785/

相关文章:

css - 如何避免iOS自动调整字体大小?

python - 安装核心 ML 工具时出错

ios - touchesBegan 与 UITapGestureRecognizer

ios - 将数值数组的特定索引与 Swift 中的 Int 变量进行比较

swift - 自更新到 Swift 1.2 以来,字典现在给出错误 'not convertible to BooleanLiteralConvertible'

ios - 变量在尝试重置时保留旧值

ios - IOS上的字符串编码问题

ios - Swift:当对象在一个区域内时运行代码

ios - 动态改变容器的高度

ios - 类继承、重写方法以及访问父类(super class)存储的属性