我试图以下列方式计算行驶的总距离:
if startLocation == nil {
startLocation = locations.first
} else {
if let lastLocation = locations.last {
let distance = startLocation.distance(from: lastLocation)
travelledDistance += distance
startLocation = lastLocation
print( "\(startLocation)")
print( "\(lastLocation)")
print("FULL DISTANCE: \(travelledDistance)")
print("STRAIGHT DISTANCE: \(distance)")
}
}
我不确定这是否仅仅是模拟器问题,但在开始时,2个位置之间的距离(计算直线距离)非常大(约1.5公里),最终它们变得更准确(+ - 15米)。 谁能帮忙解决这个问题?感谢