0

I am following this doc Lrm-google to use google direction api with leaflet routing machine. I haven't changed much of my code except replacing geocoder: L.Control.Geocoder.nominatim(), with router: L.Routing.google(), my code works when i switch back to geocoder: L.Control.Geocoder.nominatim() - the routes appears. But when I use L.Routing.google(), I get this error in my console - Uncaught TypeError: Cannot read property 'decode' of undefined

    this.control = L.Routing.control({
      waypoints: [
        L.latLng(myLocation.lat, myLocation.lon),
        L.latLng(closest_latlng.lat, closest_latlng.lng)
      ],
      // geocoder: L.Control.Geocoder.nominatim(),
      router: L.Routing.google(),
      reverseWaypoints: true,
      showAlternatives: true,
      lineOptions: {
        styles: [
          { color: "black", opacity: 0.15, weight: 9 },
          { color: "white", opacity: 0.8, weight: 6 },
          { color: "steelblue", opacity: 1, weight: 4 }
        ]
      },
      altLineOptions: {
        styles: [
          { color: "black", opacity: 0.15, weight: 9 },
          { color: "white", opacity: 0.8, weight: 6 },
          { color: "hotpink", opacity: 1, weight: 4 }
        ]
      },
      missingRouteStyles: {
        styles: [
          { color: "black", opacity: 0.15, weight: 7 },
          { color: "white", opacity: 0.6, weight: 4 },
          { color: "gray", opacity: 0.8, weight: 2, dashArray: "7,12" }
        ]
      }
    }).addTo(map);
  • Dou you have Google Directions API key? Have you included it as per docs: github.com/DerGuteWolf/lrm-google? – TomazicM Jul 9 at 5:29
  • yeah I have added my API key – Code Ninja Jul 9 at 9:53
  • Have you tried example that comes with lrm-Google plugin (with your API key of course)? – TomazicM Jul 9 at 10:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.