Created
December 15, 2012 17:29
-
-
Save anonymous/4297411 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
<script> | |
var directionsDisplay; | |
var directionsService = new google.maps.DirectionsService(); | |
var map; | |
function initialize() { | |
directionsDisplay = new google.maps.DirectionsRenderer(); | |
var chicago = new google.maps.LatLng(41.850033, -87.6500523); | |
var mapOptions = { | |
zoom: 6, | |
mapTypeId: google.maps.MapTypeId.ROADMAP, | |
center: chicago | |
} | |
map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions); | |
directionsDisplay.setMap(map); | |
} | |
function calcRoute() { | |
var start = document.getElementById("start").value; | |
var end = document.getElementById("end").value; | |
var waypts = []; | |
var checkboxArray = document.getElementById("waypoints"); | |
for (var i = 0; i < checkboxArray.length; i++) { | |
if (checkboxArray.options[i].selected == true) { | |
waypts.push({ | |
location:checkboxArray[i].value, | |
stopover:true | |
}); | |
} | |
} | |
var request = { | |
origin: start, | |
destination: end, | |
waypoints: waypts, | |
optimizeWaypoints: true, | |
travelMode: google.maps.TravelMode.DRIVING | |
}; | |
directionsService.route(request, function(response, status) { | |
if (status == google.maps.DirectionsStatus.OK) { | |
directionsDisplay | |
= new google.maps | |
.DirectionsRenderer({panel:document.getElementById('directions_panel')}); | |
} | |
}); | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment