Adding distances between coordinates in a growing array

160 Views Asked by At

I have an array which implements new coordinates every second into my location array. I am trying to add up the distances between each location point and carry this process on as new coordinates are implemented into the array.

I want to use the CLLocationDistance function

as an example:

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

now I know I can use:

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

print(Distance)

for each point, but I want to use a 'for' statement and indices to calculate all the distances between points of the growing array.

1

There are 1 best solutions below

0
Kathiresan Murugan On

Calculate distance from two locations

By using

let distance = fromLocation.distanceFromLocation(toLocation

After Append new distance to total distance