how to show 2 point destination on google map js code stack overflow
function renderDirections(result, map) {
var directionsRenderer1 = new google.maps.DirectionsRenderer({
directions: result,
routeIndex: 0,
map: map,
polylineOptions: {
strokeColor: "green"
}
});
console.log("routeindex1 = ", directionsRenderer1.getRouteIndex());
var directionsRenderer2 = new google.maps.DirectionsRenderer({
directions: result,
routeIndex: 1,
map: map,
polylineOptions: {
strokeColor: "blue"
}
});
console.log("routeindex2 = ", directionsRenderer2.getRouteIndex()); //line 17
}
function calculateAndDisplayRoute(origin, destination, directionsService, directionsDisplay, map) {
directionsService.route({
origin: origin,
destination: destination,
travelMode: google.maps.TravelMode.DRIVING,
provideRouteAlternatives: true
}, function(response, status) {
if (status === google.maps.DirectionsStatus.OK) {
renderDirections(response, map);
} else {
window.alert('Directions request failed due to ' + status);
}
});
}
function initialize() {
var directionsService = new google.maps.DirectionsService();
var directionsDisplay = new google.maps.DirectionsRenderer();
var map = new google.maps.Map(
document.getElementById("map_canvas"), {
center: new google.maps.LatLng(37.4419, -122.1419),
zoom: 13,
mapTypeId: google.maps.MapTypeId.ROADMAP
});
directionsDisplay.setMap(map);
calculateAndDisplayRoute(new google.maps.LatLng(51.61793418642200, -0.13678550737318), new google.maps.LatLng(51.15788846699750, -0.16364536053269), directionsService, directionsDisplay, map);
}
google.maps.event.addDomListener(window, "load", initialize);
Are there any code examples left?
New code examples in category Javascript
-
Javascript 2023-04-21 22:52:36
-
Javascript 2022-03-27 22:25:20 javascript download string as file
-
Javascript 2022-03-27 21:40:22 sort numbers in array javascript
-
Javascript 2022-03-27 21:20:04 compare two arrays and return the difference javascript
-
Javascript 2022-03-27 21:15:02 javascript regex french phone number
-
Javascript 2022-03-27 21:05:03 cypress custom error message
-
Javascript 2022-03-27 21:00:05 create element javascript with id
-
Javascript 2022-03-27 20:40:57 feather icons react
-
Javascript 2022-03-27 20:20:01 how to make graphql request in axios
-
Javascript 2022-03-27 20:15:07 bootstrap validator password and confirm password