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

Search (fuzzy/geometry/along-route/autocomplete)

The TomTom Maps SDK provides three powerful search services that help you find places, addresses, and points of interest with different search strategies optimized for various use cases. Each search type is designed to handle specific user interaction patterns and application requirements.

Available Search Types

Fuzzy Search

Comprehensive search that handles typos, variations in queries, and natural language input. Fuzzy search is robust and forgiving, making it ideal for situations where users might not know exact spellings or when dealing with international locations.

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

const results = await search({
    query: 'coffe shop near dam square',  // Handles typos and variations
    position: [4.9041, 52.3676]
});

Advanced Capabilities:

Ideal Applications:

Geometry Search

Find places within specific geographic boundaries or custom areas. Geometry search enables location discovery within precisely defined regions, making it perfect for area-specific applications and location-based services.

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

// Search within a circle
const results = await search({
    query: 'restaurants',
    geometries: [{
        type: 'Circle',
        coordinates: [4.9041, 52.3676], // [longitude, latitude]
        radius: 5000                     // meters
    }]
});

// Search within a GeoJSON polygon
const results = await search({
    query: 'museums',
    geometries: [{
        type: 'Polygon',
        coordinates: [[[4.7, 52.2], [5.1, 52.2], [5.1, 52.5], [4.7, 52.5], [4.7, 52.2]]]
    }]
});

The search() function automatically dispatches to geometry search when geometries is provided, and to fuzzy search otherwise.

Geometric Search Options:

Perfect For:

Along-Route Search

Discover places of interest along a planned route, filtered to a maximum detour time. Along-route search is ideal for trip planning scenarios where users want to find fuel stops, restaurants, or EV charging stations without significantly deviating from their journey.

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

// Pass a GeoJSON LineString directly
const results = await search({
    route: {
        type: 'LineString',
        coordinates: [
            [4.9, 52.37],  // Amsterdam [longitude, latitude]
            [4.95, 52.28],
            [5.0, 52.15],
            [5.1, 52.09],  // Utrecht
        ]
    },
    maxDetourTimeSeconds: 600,
    poiCategories: ['ELECTRIC_VEHICLE_STATION'],
    limit: 10,
});

// Or pass a Route Feature returned by calculateRoute
import { calculateRoute } from '@tomtom-org/maps-sdk/services';

const routes = await calculateRoute({ locations: [amsterdamWaypoint, utrechtWaypoint] });
const results = await search({
    route: routes.features[0],
    maxDetourTimeSeconds: 600,
    query: 'cafe',
});

The search() function dispatches to along-route search when a route is provided.

Key Features:

Ideal Applications:

Autocomplete Search

Perfect for search-as-you-type experiences with instant suggestions, autocomplete search provides real-time results as users type their queries. This service is optimized for speed and relevance, making it ideal for interactive search interfaces.

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

const suggestions = await autocompleteSearch({
    query: 'coffee',
    position: [4.9041, 52.3676], // Amsterdam
    resultType: ['category', 'brand', 'plaintext']
});

Key Features:

Parameter Reference

Common Parameters

These parameters apply to fuzzy search, geometry search, and along-route search:

Parameter Type Description
query string (optional) Search query text. Omit when searching purely by poiCategories, poiBrands, fuelTypes, or geometry.
limit number Maximum results to return (1–100, default: 10).
countries string[] Restrict results to specific countries using ISO 3166-1 alpha-2 or alpha-3 codes (e.g. ['NL', 'DE']).
poiCategories POICategory[] Filter results by POI category. Use the getPOICategories service to discover available values. See POI Categories.
poiBrands string[] Filter by brand name (case-sensitive). Example: ['Starbucks', 'Costa Coffee'].
indexes SearchIndexType[] Which indexes to search. Options: 'Geo', 'PAD', 'Addr', 'Str', 'XStr', 'POI'. Defaults to all.
openingHours OpeningHoursMode Include opening hours in results (e.g. 'nextSevenDays').
timeZone TimeZoneRequest Include timezone info. Use 'iana' to receive IANA timezone IDs (e.g. 'Europe/Amsterdam').
relatedPois RelatedPoisRequest Include related POIs in results. Options: 'off' (default), 'child', 'parent', 'all'.
connectors ConnectorType[] Filter EV charging stations by connector type (e.g. ['IEC62196Type2CCS', 'Chademo']).
fuelTypes Fuel[] Filter fuel stations by fuel type (e.g. ['Petrol', 'Diesel', 'E85']).
minPowerKW number Minimum EV charging power in kilowatts.
maxPowerKW number Maximum EV charging power in kilowatts.
view View Geopolitical view for disputed territories. Options: 'Unified', 'AR', 'IN', 'PK', 'IL', 'MA', 'RU', 'TR', 'CN'.
mapcodes MapcodeType[] Request mapcode formats in results: 'Local', 'International', 'Alternative'.
extendedPostalCodesFor SearchIndexType[] Include extended postal codes for specific indexes (default: all except 'Geo').
geographyTypes GeographyType[] Filter results to specific geography types (e.g. ['Municipality', 'Neighbourhood']).

Fuzzy Search Parameters

In addition to all common parameters, fuzzy search supports:

Parameter Type Description
position HasLngLat Bias results toward this location. Accepts a [longitude, latitude] pair, a GeoJSON Point, a Feature<Point>, or any Place from a previous search result. Required for radiusMeters.
radiusMeters number Constrain results to this radius around position (in meters). Requires position.
boundingBox [minLng, minLat, maxLng, maxLat] Restrict results to a rectangular geographic area.
typeahead boolean Enable predictive/autocomplete mode for partial queries (default: false).
offset number Pagination offset, zero-based (default: 0).
minFuzzyLevel number Minimum fuzziness level (1–4, default: 1). Lower values require closer matches.
maxFuzzyLevel number Maximum fuzziness level (1–4, default: 2). Higher values tolerate more typos.

Geometry Search Parameters

In addition to all common parameters, geometry search requires:

Parameter Type Description
geometries SearchGeometryInput[] Required. One or more geometries to search within. Supports Circle, Polygon, and MultiPolygon.

Note: Geometry search does not support position. The geometry shapes define the search area.

Along-Route Search Parameters

Along-route search requires route and maxDetourTimeSeconds. All common parameters also apply. position is not available — the route geometry defines where to search. Parameters from fuzzy/geometry search such as boundingBox, radiusMeters, geometries, and offset also do not apply.

Parameter Type Description
route LineString | Position[] | Route Required. The route to search along. Accepts a GeoJSON LineString, an array of [longitude, latitude] positions, or a Route Feature returned by calculateRoute.
maxDetourTimeSeconds number Required. Maximum allowed detour time in seconds (positive integer).
sortBy 'detourTime' | 'detourOffset' Sort results by minimum detour time or by position along the route.

Autocomplete Search Parameters

Parameter Type Description
query string Partial user input to autocomplete.
position HasLngLat Bias suggestions toward this location. Accepts a [longitude, latitude] pair, a GeoJSON Point, a Feature<Point>, or a Place.
limit number Maximum suggestions to return (1–100, default: 10).
radiusMeters number Constrain suggestions to this radius around position.
countries string[] Restrict to specific countries.
resultType AutocompleteSearchSegmentType[] Filter suggestion types: 'brand', 'category', 'plaintext'.

POI Categories

Use poiCategories to filter results to specific types of places. Each value must be a POICategory enum constant. Use the getPOICategories service to search and browse available categories by name or synonym, then pass the resulting code values directly here.

import { search, getPOICategoryCodes } from '@tomtom-org/maps-sdk/services';

// Filter to a known category
const italian = await search({
    position: [4.9041, 52.3676],
    radiusMeters: 1000,
    poiCategories: ['ITALIAN_RESTAURANT']
});

// Discover categories first, then search
const restaurantCodes = await getPOICategoryCodes({ filters: ['restaurant'] });
const restaurants = await search({
    position: [4.9041, 52.3676],
    radiusMeters: 1000,
    poiCategories: restaurantCodes
});

// EV charging with connector and power filtering
const evChargers = await search({
    position: [4.9041, 52.3676],
    radiusMeters: 5000,
    poiCategories: ['ELECTRIC_VEHICLE_STATION'],
    connectors: ['IEC62196Type2CCS', 'Tesla'],
    minPowerKW: 50
});

Example category values: ITALIAN_RESTAURANT, GAS_STATION, HOTEL, PHARMACY, MUSEUM, PARKING_GARAGE, ELECTRIC_VEHICLE_STATION, SHOPPING_CENTER. See the POICategory type for the full list, or use the getPOICategories service to search and explore them at runtime.

Working with Search Results

Search results follow a GeoJSON FeatureCollection structure. Each feature is a GeoJSON Feature<Point> with place data in properties:

const results = await search({
    query: 'coffee',
    position: [4.9041, 52.3676]
});

results.features.forEach(place => {
    console.log(place.properties.poi?.name);              // Business name (POI results)
    console.log(place.properties.address.freeformAddress);// Formatted address
    console.log(place.geometry.coordinates);              // [longitude, latitude]
    console.log(place.properties.poi?.categories);        // POICategory[] (e.g. ['CAFE'])
    console.log(place.properties.poi?.localizedCategories); // string[] (e.g. ['café'])
    console.log(place.properties.score);                  // Relevance score
    console.log(place.properties.distance);               // Distance in meters (if position was given)
});

To retrieve only the first result, use searchOne() — it throws if no results are found:

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

const place = await searchOne('Eiffel Tower');
console.log(place.properties.poi?.name); // 'Eiffel Tower'

Examples

Find Bus Stops in an Area (Node.js)

Use boundingBox to search for all bus stops within a rectangular geographic area. This example searches the Amsterdam city area:

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

const results = await search({
    poiCategories: ['BUS_STOP'],
    boundingBox: [4.72, 52.27, 5.07, 52.43], // [minLng, minLat, maxLng, maxLat]
    limit: 100
});

results.features.forEach(stop => {
    const [lng, lat] = stop.geometry.coordinates;
    console.log(`${stop.properties.poi?.name} — ${lng}, ${lat}`);
});

Integration with Map Visualization

Search results can be directly integrated with the TomTom Maps SDK for immediate visual representation:

import { TomTomMap, PlacesModule } from '@tomtom-org/maps-sdk/map';

const map = new TomTomMap({ mapLibre: { container: 'map' } });
const placesModule = await PlacesModule.get(map);

const results = await search({
    query: 'museums',
    position: [4.9041, 52.3676]
});

// Display search results as markers on the map
await placesModule.show(results);

Performance Optimization

For optimal performance in production applications, consider these best practices:

Search Strategy Selection:

Result Limiting:

For complete search implementation examples and advanced usage patterns, go to http://docs.tomtom.com/maps-sdk-js/examples.

Related Guides and Examples

Map Integration

Related Examples

Related Services