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
Places Services
Search, geocoding, and reverse geocoding functionality:
import { search, geocode, reverseGeocode } 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 optimization:
import { calculateRoute } from '@tomtom-org/maps-sdk/services';
const route = await calculateRoute({ locations: [ [4.9041, 52.3676], // Amsterdam [2.3522, 48.8566] // Paris ]});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, reverse geocoding
- Routing Services - Route calculation and optimization
- Customizing Services - Configuration options