This is the documentation of version 0.64.0. Go to the latest version, 1.0.0-rc.5.

Locations

locations is the ordered list a route passes through. Each entry is one of two kinds:

A request needs at least two waypoints, or one path on its own.

Maximum 150 waypoints per route.

Single point waypoints

Coordinate pairs

[longitude, latitude] pairs:

import { calculateRoute } from '@tomtom-org/maps-sdk/services';

const routes = await calculateRoute({
    locations: [
        [4.897070, 52.377956],  // Amsterdam
        [4.288788, 52.078663],  // The Hague
        [4.462456, 51.926517]   // Rotterdam
    ]
});

GeoJSON points and features

A GeoJSON Point, or any Feature<Point>, is a waypoint too — so geocoding and search results go in unchanged:

import { calculateRoute, geocodeOne } from '@tomtom-org/maps-sdk/services';

const waypoints = await Promise.all([
    geocodeOne('Amsterdam, Netherlands'),
    geocodeOne('The Hague, Netherlands'),
    geocodeOne('Rotterdam, Netherlands')
]);

const routes = await calculateRoute({ locations: waypoints });

Path arrays

A path forces the route along given coordinates. Its first and last points become stops as well, so it shapes the route without removing a leg:

import { calculateRoute } from '@tomtom-org/maps-sdk/services';

const routes = await calculateRoute({
    locations: [
        [4.9, 52.3],  // Origin waypoint
        [
            [4.85, 52.25],  // Path points
            [4.80, 52.20],
            [4.75, 52.15]
        ],
        [4.5, 51.9]   // Destination waypoint
    ]
});

A route feature from an earlier call is a path as well, and keeps its leg boundaries as stops:

const utrechtToRotterdam = await calculateRoute({
    locations: [[5.1230, 52.0919], [4.4624, 51.9265]]
});

const routes = await calculateRoute({
    locations: [
        [4.8970, 52.3779], // Amsterdam
        utrechtToRotterdam.features[0],
        [2.3522, 48.8566]  // Paris
    ]
});

Displaying waypoints on map

RoutingModule.showWaypoints takes the same list, and clearWaypoints removes the pins:

await routingModule.showRoutes(routes);
await routingModule.showWaypoints(waypoints);

Waypoints in the routing module guide covers the pins, their labels and their events. Inserting a stop at the best position in an existing list is a core route utility.

API reference

Related guides and examples

Related guides

Related examples