Skip to content
First route

First route

Request

Coordinates are always lon,lat, separated by ;.

curl -s -H "Authorization: Bearer YOUR_TOKEN" "https://api.mapx.at/v1/directions/driving/16.3725,48.2085;15.3294,48.2272?overview=false" \
  | jq '.routes[0] | {distance, duration}'

distance is in meters, duration in seconds. Other profiles: driving-truck, cycling, walking. See the Navigation guide.

Draw it on the map

With the map from First map in map:

const url = "https://api.mapx.at/v1/directions/driving/16.3725,48.2085;15.3294,48.2272?overview=simplified&access_token=YOUR_TOKEN";
const route = (await (await fetch(url)).json()).routes[0];
map.on("load", () => {
  map.addSource("route", { type: "geojson", data: { type: "Feature", geometry: route.geometry } });
  map.addLayer({ id: "route", type: "line", source: "route", paint: { "line-color": "#1d5bd8", "line-width": 5 } });
  map.fitBounds([[15.3294, 48.2085], [16.3725, 48.2272]], { padding: 40 });
});

Next