Skip to main content
Directions returns one or more routes between two or more points, each carrying its geometry as an encoded polyline plus distance and time estimates.

Requesting a route

string[]
required
Waypoints as "lat,lon" strings. Repeat the parameter once per point; at least two are required, and intermediate points are supported.
string
required
One of car, bike or foot.
boolean
default:"false"
Return alternative routes alongside the best one.
boolean
default:"false"
Include a turn-by-turn instruction list. Without this, instructionList is null.
points[] uses "lat,lon" order, unlike the [lon, lat] arrays MapLibre expects. polyline.toGeoJSON() produces renderer-ready [lon, lat] coordinates, so the conversion only bites on the request side.

Drawing the route

To frame the whole route, fit the camera to its bounds:

Reading the response

string
Route geometry in encoded polyline format. Decode with @mapbox/polyline before rendering.
number
Total route distance.
integer
Estimated travel time in milliseconds — divide by 1000 before formatting as seconds.
array | null
Turn-by-turn instructions, or null unless you requested instructions=true.

Next

Directions API

Full parameter reference and playground.

Core concepts

More on encoded polylines and coordinate order.