2017-06-14 33 views
0

我有一個數組,每秒鐘在我的位置數組中實現新的座標。我試圖將每個位置點之間的距離加起來,並將這個過程作爲新座標實現到數組中。在不斷增加的陣列中添加座標之間的距離

我想用CLLocationDistance功能

爲例:

var Array = [Double](-1.0, 1.0, -2.0, 2.0, -3.0, 3.0) 

現在我知道我可以使用:

let Distance = (Latitude:-1.0, Longitude:1.0.distance(from: (Latitude:-2.0, Longitude:2.0)) 

print(Distance) 

每個點,但我想用一個'for'語句和索引來計算不斷增長的數組中點之間的所有距離。從兩個位置

+3

難道一個'[CLLocationCoordinates2D]'是一個更適合用於這一目的? – Sweeper

回答

0

計算距離使用

let distance = fromLocation.distanceFromLocation(toLocation 

追加新的距離後,以總距離