-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdirections.html
42 lines (33 loc) · 1.59 KB
/
directions.html
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<!DOCTYPE html>
<html>
</head>
</head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js">
</script>
<body>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js">
var printOut;
jQuery.when(
jQuery.getJSON('https://api.mapbox.com/v4/directions/mapbox.driving/-122.42,37.78;-77.03,38.91.json?access_token=pk.eyJ1IjoiamVyaWNvZGUiLCJhIjoiY2llaTlzcHRnMDBqbHNybTFndDAweno5cyJ9.gPQQaYjYiDgLrkpDQ7YKTA')
).done( function(json) {
console.log(json.routes[0].steps);
arrayOfSteps = json.routes[0].steps;
printOut = "Route from " + json.origin.properties.name + " to " + json.destination.properties.name + "\n";
printOut += "Distance: " + (json.routes[0].distance * .00062).toFixed(2) + " miles \n";
printOut += "Duration: " + (json.routes[0].duration / 60).toFixed(2) + " minutes \n";
printOut += "Summary: " + json.routes[0].summary + "\n";
printOut += "From your start destination: \n\n";
for (i = 0; i < arrayOfSteps.length; i++){
if (i == arrayOfSteps.length - 1){
printOut += arrayOfSteps[i].maneuver.instruction;
}else{
printOut += arrayOfSteps[i].maneuver.instruction + " for " +
(arrayOfSteps[i].duration / 60).toFixed(2) + " minutes ---- " +
(arrayOfSteps[i].distance * .00062).toFixed(2) + " miles \n\n";
}
}
alert(printOut);
});
</script>
</body>
</html>