Created
December 11, 2019 15:01
-
-
Save crstn/1113240d99578d2877bd07d6e6a790b2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function calculateAndDisplayRoute1(directionsService, directionsRenderer1) { | |
var mode = document.getElementById("mode").value; | |
var start = document.getElementById("ac1").value; | |
var end = document.getElementById("ac4").value; | |
directionsService.route({ | |
origin: start, | |
destination: end, | |
travelMode: google.maps.TravelMode[mode] | |
}, | |
function(response, status) { | |
if (status == "OK") { | |
route_length = response.routes[0].overview_path.length; | |
urlorigin = | |
"/origin?lat=" + | |
response.routes[0].overview_path[0].lat() + | |
"&lng=" + | |
response.routes[0].overview_path[0].lng(); | |
// also using the /origin app route here! | |
urldestination = | |
"/origin?lat=" + | |
response.routes[0].overview_path[route_length - 1].lat() + | |
"&lng=" + | |
response.routes[0].overview_path[route_length - 1].lng(); | |
console.log(urlorigin); | |
console.log(urldestination); | |
// turns ot we DO need jQuery's ajax function | |
$.ajax({ | |
url: urlorigin, | |
}).done(function(data) { | |
// use addGeoJson instead of loadGeoJson: | |
map.data.addGeoJson(data); | |
// ...do more with the data here to fill in the boxes at the bottom | |
// when the first query is complete and processed, | |
// head on to the second one. Thay way you can have just one | |
// app route in the server.py: | |
}).then(function(){ | |
// same thing as before, but for the destination | |
$.ajax({ | |
url: urldestination, | |
}).done(function(data) { | |
map.data.addGeoJson(data); | |
// Do more with the data here to fill in the boxes at the bottom | |
}); | |
}); | |
directionsRenderer1.setDirections(response); | |
} else { | |
window.alert("Directions request failed due to " + status); | |
} | |
} | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment