-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprintDirections.js
52 lines (44 loc) · 1.9 KB
/
printDirections.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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
$(document).ready(function() {
$('#printDirections').click(function() {
var printOut;
// Need to pull from current location
var fromlong = "-90.199404"
var fromlat = "38.627003"
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function(position) {
fromlat = position.coords.latitude
fromlng = position.coords.longitude
}
)};
// Need to pull from court location
var tolong = "-90.341026"
var tolat = "38.649552"
jQuery.when(
jQuery.getJSON('https://api.mapbox.com/v4/directions/mapbox.driving/' + fromlong +
',' + fromlat + ';' + tolong + ',' + tolat +
'.json?access_token=pk.eyJ1IjoiamVyaWNvZGUiLCJhIjoiY2llaTlzcHRnMDBqbHNybTFndDAweno5cyJ9.gPQQaYjYiDgLrkpDQ7YKTA')
).done( function(json) {
console.log(json.routes[0].steps);
arrayOfSteps = json.routes[0].steps;
if (json.origin.properties.name != "" && json.destination.properties.name != ""){
printOut = "Route from " + json.origin.properties.name + " to " + json.destination.properties.name + ">>>>\n";
}else{
printOut = "Route >>>> \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);
});
});
});