|
|
@ -1,7 +1,7 @@ |
|
|
|
import haversineDistance from 'haversine-distance'; |
|
|
|
import haversineDistance from 'haversine-distance'; |
|
|
|
import { Coordinates } from './types'; |
|
|
|
import { Waypoint } from './types'; |
|
|
|
|
|
|
|
|
|
|
|
export const getRouteLength = (points: Coordinates[]) => { |
|
|
|
export const getRouteLength = (points: Waypoint[]) => { |
|
|
|
let result = 0; |
|
|
|
let result = 0; |
|
|
|
for (let i = 0; i < points.length; i++) { |
|
|
|
for (let i = 0; i < points.length; i++) { |
|
|
|
const currentPoint = points[i]; |
|
|
|
const currentPoint = points[i]; |
|
|
@ -9,7 +9,10 @@ export const getRouteLength = (points: Coordinates[]) => { |
|
|
|
if (!currentPoint || !previousPoint) { |
|
|
|
if (!currentPoint || !previousPoint) { |
|
|
|
continue; |
|
|
|
continue; |
|
|
|
} |
|
|
|
} |
|
|
|
result += haversineDistance(previousPoint, currentPoint); |
|
|
|
result += haversineDistance( |
|
|
|
|
|
|
|
previousPoint.coordinates, |
|
|
|
|
|
|
|
currentPoint.coordinates, |
|
|
|
|
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return result; |
|
|
|
return result; |
|
|
|