0

i have draw routes from Point A to Point B. I am not able to show route information on routes same as appears in google-map.

i need to make it look alike as google map.

and when user click on any route, same route should show selected.

left image custom, right image google maps

Following are the code.

function calculateRoutes(pierLocation, destinationLocation) {
  var request = {
    origin: document.getElementById("from").value,
    destination: document.getElementById("to").value,
    travelMode: "DRIVING",
    provideRouteAlternatives: true,
    unitSystem: google.maps.UnitSystem.IMPERIAL,
  };

  directionsService.route(request, function (result, status) {
    if (status === "OK") {
      directionsDisplay.setDirections(result);
      var summaryPanel = document.getElementById("directions-panel");
      summaryPanel.innerHTML = "";

      for (var x = 0; x < result.routes.length; x++) {
        new google.maps.DirectionsRenderer({
          map: map,
          directions: result,
          routeIndex: x,
        });

        summaryPanel.innerHTML += "<hr><br><b> Route " + (x + 1) + ":<br>";
        var route = result.routes[x];
        for (var y = 0; y < route.legs.length; y++) {
          var routeSegment = y + 1;
        }
      }
    } else {
      window.alert("Directions request failed due to " + status);
    }
  });
}
Mushroomator
  • 6,516
  • 1
  • 10
  • 27
Developer
  • 99
  • 1
  • 4
  • Is this infoWindow related to traffic layer. I think this information is linked with enabling traffic on google maps – B Kalra Apr 14 '22 at 12:51
  • possible duplicate of [Adding InfoWindow on Google directions route](https://stackoverflow.com/questions/30648228/adding-infowindow-on-google-directions-route) – geocodezip Apr 14 '22 at 13:48
  • related question: [Google Maps click event on route](https://stackoverflow.com/questions/17902574/google-maps-click-event-on-route) – geocodezip Apr 14 '22 at 13:49

0 Answers0