forked from mdrmuhaimin/Travelive
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcalcSetDistance.js
27 lines (22 loc) · 931 Bytes
/
calcSetDistance.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
function calcSetDistance(directionResult) {
var myRoute = directionResult.routes[0].legs[0];
var spacing = 50000; //distance is measured in meters
var runningTotal = spacing;
//Export coordinates as array
var coordinates = new Array();
for(var i = 0; i < myRoute.steps.length; i++) {
var stepDistance = myRoute.steps[i].distance.value;
runningTotal -= stepDistance;
if(runningTotal < 0) { //If less than 0, then in this path, we are passing the spacing mark
var distancePerPoint = stepDistance / myRoute.steps[i].path.length;
var goodPoint = myRoute.steps[i].path[abs(runningTotal) / distancePerPoint]; //Get point that is the right spacing away
coordinates.push(goodPoint); //Add to our coordinates
runningTotal = spacing;
}
if(i = myRoute.steps.length - 1) {
//Add last point to route even if not past spacings
coordinates.push(myRoute.steps[i].end_location);
}
}
return coordinates;
}