how to show 2 point destination on google map js code stack overflow

Solutions on MaxInterview for how to show 2 point destination on google map js code stack overflow by the best coders in the world

showing results for - "how to show 2 point destination on google map js code stack overflow"
Matilda
16 Feb 2018
1function renderDirections(result, map) {
2  var directionsRenderer1 = new google.maps.DirectionsRenderer({
3    directions: result,
4    routeIndex: 0,
5    map: map,
6    polylineOptions: {
7      strokeColor: "green"
8    }
9  });
10  console.log("routeindex1 = ", directionsRenderer1.getRouteIndex());
11
12  var directionsRenderer2 = new google.maps.DirectionsRenderer({
13    directions: result,
14    routeIndex: 1,
15    map: map,
16    polylineOptions: {
17      strokeColor: "blue"
18    }
19  });
20  console.log("routeindex2 = ", directionsRenderer2.getRouteIndex()); //line 17
21}
22
23function calculateAndDisplayRoute(origin, destination, directionsService, directionsDisplay, map) {
24  directionsService.route({
25    origin: origin,
26    destination: destination,
27    travelMode: google.maps.TravelMode.DRIVING,
28    provideRouteAlternatives: true
29  }, function(response, status) {
30    if (status === google.maps.DirectionsStatus.OK) {
31      renderDirections(response, map);
32    } else {
33      window.alert('Directions request failed due to ' + status);
34    }
35  });
36}
37
38function initialize() {
39  var directionsService = new google.maps.DirectionsService();
40  var directionsDisplay = new google.maps.DirectionsRenderer();
41  var map = new google.maps.Map(
42    document.getElementById("map_canvas"), {
43      center: new google.maps.LatLng(37.4419, -122.1419),
44      zoom: 13,
45      mapTypeId: google.maps.MapTypeId.ROADMAP
46    });
47  directionsDisplay.setMap(map);
48  calculateAndDisplayRoute(new google.maps.LatLng(51.61793418642200, -0.13678550737318), new google.maps.LatLng(51.15788846699750, -0.16364536053269), directionsService, directionsDisplay, map);
49
50
51}
52google.maps.event.addDomListener(window, "load", initialize);