Search code examples
leafletshortest-pathpolyline

How to get a polyline for shortest path between two points in leaflet?


I am new in leaflet and I need to create a layer for shortest path between nodes. I also need the polyline for some other calculations. I tried some plugins which just display the shortest path on map but does not provide furthur details(polyline, point-to-point ...) for the optimal route. Is there any way that I can get the data? any plugin or trick ...?


Solution

  • You want to use some geocoding (see http://leafletjs.com/plugins.html#geocoding ) to turn addresses into lat-lng coordinates, then route finding ( http://leafletjs.com/plugins.html#routing ) to find the shortest path constrained by a street network.

    I tried some plugins which just display the shortest path on map but does not provide furthur details

    Then don't use a routing plugin and use the routing APIs (OSRM, GraphHopper, MapBox directions) directly. It will obviously involve more work but you will have a finer control.