Skip to content

Get directions

Point-to-point directions over the Canada road graph. route() returns the distance in metres, the duration in seconds, and a GeoJSON LineString you can add as a source.

live result
the code that produced it
import { Unmap } from "@unmap/sdk";

const unmap = new Unmap({
  key: "um_live_...",
  container: "map",
  center: [-114.03, 51.07],
  zoom: 11,
});

const route = await unmap.router.route([-114.0719, 51.0447], [-113.9871, 51.0899], { mode: "auto" });

unmap.map!.on("load", () => {
  unmap.map!.addSource("route", {
    type: "geojson",
    data: { type: "Feature", properties: {}, geometry: route.geometry },
  });
  unmap.map!.addLayer({
    id: "route-line",
    type: "line",
    source: "route",
    layout: { "line-cap": "round", "line-join": "round" },
    paint: { "line-color": "#FF3E9A", "line-width": 3 },
  });
});

Coordinates are [lng, lat]. There are no intermediate waypoints: a request carries exactly two points. The first and last coordinates of the geometry are snapped to the nearest routable edge, so they sit near the points you asked for rather than exactly on them.

The road network covers Canada only. A point in the United States is 422 outside_coverage. Iqaluit is inside Canada and is not road-connected to the mainland, so Calgary to Iqaluit is 422 no_route.

The Routing API documents every parameter, including the truck vehicle profile. @unmap/routing is the same client with no map dependency.