Services quickstart
The Services bundle provides a comprehensive set of GeoJSON-based functions for accessing TomTom’s location APIs. These services can be used in any JavaScript-based application, from web browsers to Node.js servers.
Installing Dependencies
# npm or Yarn - automatic peer dependency installationnpm install @tomtom-org/maps-sdk
# pnpm - enable auto-install-peers for easiest setupecho "auto-install-peers=true" >> .npmrcpnpm install @tomtom-org/maps-sdkPeer dependencies (installed automatically with above commands):
lodash-es(v4) - Utility functionszod(v4) - Schema validation
For more details, see the Project setup guide.
Setup
import { TomTomConfig } from '@tomtom-org/maps-sdk/core';
TomTomConfig.instance.put({ apiKey: 'YOUR_API_KEY_HERE'});Available Services
All services are imported from @tomtom-org/maps-sdk/services and return GeoJSON.
Places Services
Search, geocoding, POIs, and EV charging:
import { search, // free-form and category search geocode, // address → coordinates reverseGeocode, // coordinates → address autocompleteSearch, // type-ahead suggestions alongRouteSearch, // search along a route geometry explorationSearch, // browse POIs by category placeById, // look up a place by its id getPOICategories, // POI category tree geometryData, // administrative / geometry boundaries evChargingStationsAvailability, // live EV connector availability} from '@tomtom-org/maps-sdk/services';
// Search for placesconst results = await search({ query: 'restaurants', position: [4.9041, 52.3676]});
// Geocode addressconst location = await geocode({ query: 'Dam Square, Amsterdam'});
// Reverse geocode coordinatesconst address = await reverseGeocode({ position: [4.9041, 52.3676]});Routing Services
Route calculation and reachable areas (isochrones):
import { calculateRoute, // point-to-point route calculation calculateReachableRanges, // isochrone / reachable-range polygons} from '@tomtom-org/maps-sdk/services';
const route = await calculateRoute({ locations: [ [4.9041, 52.3676], // Amsterdam [2.3522, 48.8566] // Paris ]});Traffic Services
Traffic incidents and area analytics:
import { trafficIncidentDetails, // incidents within a bounding box trafficAreaAnalytics, // aggregated traffic statistics for an area} from '@tomtom-org/maps-sdk/services';
const incidents = await trafficIncidentDetails({ bbox: [4.728, 52.278, 5.08, 52.479] // [minLon, minLat, maxLon, maxLat]});Node.js Usage
The services work identically in Node.js environments:
const { TomTomConfig } = require('@tomtom-org/maps-sdk/core');const { search, calculateRoute } = require('@tomtom-org/maps-sdk/services');
TomTomConfig.instance.put({ apiKey: process.env.TOMTOM_API_KEY});
const results = await search({ query: 'coffee shops', position: [4.9041, 52.3676]});Next Steps
- Places Services - Search, geocoding, POIs, EV charging
- Routing Services - Route calculation and reachable ranges
- Traffic Services - Incident details and area analytics
- Customizing Services - Configuration options