Draw a Route on a Map
Drawing a route takes three steps: requestgeometries=geojson, grab routes[0].geometry, hand it to your map library. No polyline decoding needed.
Leaflet (vanilla JS)
The API key above would be exposed in the browser. In production, proxy requests through your own backend (see Authentication).
Mapbox GL JS
React + react-leaflet
Drawing multiple routes (alternatives / fleets)
- Alternative routes: request
alternatives=2, iteratedata.routes[], give each a different color - Fleet Optimization: each
routes[i].geometryin the response is one vehicle’s route — color by vehicle
