我有一个 lat long 的数组,我想像dijkstra 算法一样对数组进行排序(以找到从一个位置到另一个位置的最短距离)
for i in 0..<(dataArray - 1) {
let coordinate1 = CLLocation(latitude: (dataArray[i] as AnyObject).value(forKey: "addressLatitude") as! CLLocationDegrees, longitude: (dataArray[i] as AnyObject).value(forKey: "addressLongitude") as! CLLocationDegrees)
let coordinate2 = CLLocation(latitude: (dataArray[i+1] as AnyObject).value(forKey: "addressLatitude") as! CLLocationDegrees, longitude: (dataArray[i+1] as AnyObject).value(forKey: "addressLongitude") as! CLLocationDegrees)
var distance: CLLocationDistance? = nil
distance = coordinate1.distance(from: coordinate2)
let kilometers = CLLocationDistance((distance ?? 0.0) / 1000.0)
print(kilometers)
}