Created
March 9, 2017 16:51
-
-
Save andrescabana86/d488183a5ecbe42b9f2a87727eb87b43 to your computer and use it in GitHub Desktop.
Create multiple routes in a map
This file contains hidden or 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
var location1 = new google.maps.LatLng(34.04429454929703, -118.22793351693724); | |
var location2 = new google.maps.LatLng(33.688522885631706, -116.15151750131224); | |
var location3 = new google.maps.LatLng(32.69561555501597, -117.06338273568724); | |
var location4 = new google.maps.LatLng(34.525395303965354, -117.27212297006224); | |
var map; | |
var mapOptions = { center: new google.maps.LatLng(42.5584308, -70.8597732), zoom: 3, | |
mapTypeId: google.maps.MapTypeId.ROADMAP }; | |
function initialize() { | |
map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions); | |
directionsService = new google.maps.DirectionsService(); | |
directionsDisplay = new google.maps.DirectionsRenderer({ | |
suppressMarkers: false, | |
suppressInfoWindows: true | |
}); | |
directionsDisplay.setMap(map); | |
var request = { | |
origin: location1, | |
destination: location2, | |
travelMode: google.maps.DirectionsTravelMode.DRIVING | |
}; | |
directionsService.route(request, function(response, status) { | |
if (status == google.maps.DirectionsStatus.OK) { | |
directionsDisplay.setDirections(response); | |
} | |
}); | |
//directionsService = new google.maps.DirectionsService(); | |
directionsDisplay2 = new google.maps.DirectionsRenderer({ | |
suppressMarkers: false, | |
suppressInfoWindows: true | |
}); | |
directionsDisplay2.setMap(map); | |
var request = { | |
origin: location3, | |
destination: location4, | |
travelMode: google.maps.DirectionsTravelMode.DRIVING | |
}; | |
directionsService.route(request, function(response, status) { | |
if (status == google.maps.DirectionsStatus.OK) { | |
directionsDisplay2.setDirections(response); | |
} | |
}); | |
} | |
google.maps.event.addDomListener(window, 'load', initialize); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment