perliedman / leaflet-routing-machine

Control for routing in Leaflet
https://www.liedman.net/leaflet-routing-machine/
Other
1.08k stars 350 forks source link

Unable to use Bing Geocoder, defaults to OSRM #502

Open abnagpal opened 5 years ago

abnagpal commented 5 years ago

I am trying to get route between two waypoints using leaflet routing machine with Bing Geocoder.

I was able to hit my local OSRM server when using the serviceUrl option. While using the Bing Geocoder option, the routing is being defaulted to OSRM.

I am following the example mentioned here -

let routingControl = new L.Routing.control({
        waypoints: [
            startMarker.getLatLng(),
            destMarker.getLatLng()
        ],
        show: false,
        allowUTurns: false,
        geocoder: new L.Control.Geocoder.bing(BING_MAP_KEY)
    });
routingControl.addTo(map);

routingControl.on('routesfound', function (selectedRoute) {

        console.log("Selected Route" + selectedRoute.route.coordinates);
    });

Can you help out in where I am going wrong here?

Also, I want to fetch the selected route and display the directions in a different view. Is it possible to fetch directions directly from the routing control object than going the listeners route?

perliedman commented 5 years ago

You should be able to use the geocoder and serviceUrl options together. Please post the code that does not work if you think this is actually a bug in LRM.

abnagpal commented 5 years ago

I want to use Bing for routing(getting co-ordinates and itinerary).

let routingControl = new L.Routing.control({
        waypoints: [
            startMarker.getLatLng(),
            destMarker.getLatLng()
        ],
        show: false,
        allowUTurns: false,
        geocoder: new L.Control.Geocoder.bing(BING_MAP_KEY)
    });
routingControl.addTo(map);

When I use the above code, it defaults to OSRM instead of calling BING APIs. Can you help out in where I am going wrong here?

perliedman commented 5 years ago

Ok, there is no built-in support for Bing's route service in LRM, so that will not work.

You can achieve this by writing a custom IRouter implementation that works with Bing, this had been done for numerous other routing providers before (see the GraphHopper, TomTom, Valhalla och ESRI plugins), but this is to my knowledge not something anyone has done for Bing already.