Search (autocomplete/fuzzy/geometry search)
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:
- Tolerates spelling mistakes and variations in input
- Supports natural language queries for intuitive user interaction
- Category and POI search with intelligent matching
- Flexible radius-based or bounding box search options
Ideal Applications:
- General search functionality where user input quality varies
- International applications with diverse language inputs
- Voice-to-text search implementations
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 circleconst results = await search({ query: 'restaurants', geometries: [{ type: 'Circle', coordinates: [4.9041, 52.3676], // [longitude, latitude] radius: 5000 // meters }]});
// Search within a GeoJSON polygonconst 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:
- Circle: Custom radius around a point (
type: 'Circle',coordinates,radius) - Polygon: GeoJSON polygon for custom area boundaries
- MultiPolygon: Multiple non-contiguous areas in a single query
Perfect For:
- Location discovery within specific neighborhoods or districts
- Delivery and service area applications
- Tourism and local business discovery
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:
- Real-time suggestions as users type with minimal latency
- Brand and category suggestions for enhanced user experience
- Optimized for speed with lightweight responses
- Perfect for search bars and interactive input fields
Parameter Reference
Common Parameters
These parameters apply to both fuzzy search and geometry search:
| Parameter | Type | Description |
|---|---|---|
query | string (optional) | Search query text. Omit when searching purely by poiCategories, poiBrands, fuelTypes, or geometry. |
position | [longitude, latitude] | Bias results toward this location. Required for radiusMeters. |
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 |
|---|---|---|
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. |
Autocomplete Search Parameters
| Parameter | Type | Description |
|---|---|---|
query | string | Partial user input to autocomplete. |
position | [longitude, latitude] | Bias suggestions toward this location. |
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 categoryconst italian = await search({ position: [4.9041, 52.3676], radiusMeters: 1000, poiCategories: ['ITALIAN_RESTAURANT']});
// Discover categories first, then searchconst restaurantCodes = await getPOICategoryCodes({ filters: ['restaurant'] });const restaurants = await search({ position: [4.9041, 52.3676], radiusMeters: 1000, poiCategories: restaurantCodes});
// EV charging with connector and power filteringconst 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():
import { searchOne } from '@tomtom-org/maps-sdk/services';
const place = await searchOne({ query: 'Eiffel Tower', position: [2.3522, 48.8566] });if (place) { 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 mapawait placesModule.show(results);Performance Optimization
For optimal performance in production applications, consider these best practices:
Search Strategy Selection:
- Use autocomplete for real-time search interfaces
- Use fuzzy search for comprehensive location finding
- Use geometry search for area-specific discovery
Result Limiting:
- Set appropriate
limitvalues based on UI requirements - Use
offsetfor pagination of large result sets - Cache frequent search results for faster response times
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
- Places Module - Display search results as interactive places on the map with customizable styling and user interactions
- POIs - Advanced point-of-interest visualization and filtering for search results
Related Examples
- Fuzzy Search Playground - Interactive fuzzy search with map visualization and result filtering
- Autocomplete Fuzzy Search Playground - Real-time search-as-you-type with instant map updates
- Geometry Search Playground - Search within custom geographic boundaries and areas
- Geometry Search with POI Categories - Category-filtered search within specific regions
- Places Customize - Customizing the appearance and behavior of search result markers
- Search Places in Geometry - Specialized search example for finding places in a defined area
- Search Places nearby Location - Specialized search example for finding places nearby a location
Related Services
- Geocoding - Convert search result addresses to precise coordinates for enhanced accuracy
- Reverse Geocoding - Get address information for search result coordinates