Showing directions output as leaflet geoJson layer


I was looking at the documentation for and on that page you also show the response of the API on a map by using the leaflet library. I am trying to do the same thing, but don’t know how to get from the response of the directions API to the map. The API documentation says the response is in geoJson format, but just putting the response (body) into a leaflet L.geoJSON(response).addTo(map); gets me a “Error: Invalid GeoJSON object.” Any help on how to work the API response into leaflet would be much appreciated.


The directions response is by default encodedpolyline (as per our docs).

If you specifiy format=geojson, you get a GeoJSON response.


Thank you, that helped a lot.

The main description for get directions in the docs reads: “Returns a route between two or more locations for a selected profile and its settings as GeoJSON response.” … maybe that should be changed to avoid confusion.

Best wishes,