Skip to main content

Draw a Route on a Map

Drawing a route takes three steps: request geometries=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, iterate data.routes[], give each a different color
  • Fleet Optimization: each routes[i].geometry in the response is one vehicle’s route — color by vehicle

Base map options

JustRouting returns only the route geometry — pick any base map (standard OSM tiles are free for demos):