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

落花浮王杯 提交于 2019-12-12 01:05:33

问题


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 ...?


回答1:


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.



来源:https://stackoverflow.com/questions/36140647/how-to-get-a-polyline-for-shortest-path-between-two-points-in-leaflet

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!