OSRM Route Plotting – How to Show Actual Route from osrm-backend JSON Response in Leaflet

leafletopen-source-routing-machineopenstreetmap

While trying to test routing using OSRM Demo server I sent GET request with the following url:

http://router.project-osrm.org/route/v1/driving/90.4007354,23.7936502;90.3925568,23.7746739?steps=true

When I plot the intersections on a web map with OpenStreetMap tiles in the background I get the following route.:

issue

But when I use the same cordinate in the OSRM Demo Server's front-end I get the following route:

osrm_frontend

I have also check that the JSON response from the OSRM Demo Server's front-end which is the same as the response from the url I requested. From the first screenshot we can see that the while routing the flyover is being ignored and the starting and the ending point of flyover are being connected with a straight line when plotted but that is not the case for the OSRM Demo Server's front-end. What am I doing wrong? Can anybody please help?

Best Answer

The difference is that you plot only the intersections, whereas the OSRM Demo Server plots the whole route.

To plot the whole route, use the geometry element in routes[0] in the JSON. The route is encoded using Google's polyline algorithm.

If you want the route as GEOJSON linestring instead of the encoded polyline, add &geometries=geojson to your request.