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 bounding boxconst results = await search({ query: 'restaurants', boundingBox: [4.7, 52.2, 5.1, 52.5] // Amsterdam area bounds});Geometric Search Options:
- Custom geometric boundaries using GeoJSON polygons
- City and neighborhood-based searches within administrative boundaries
- Bounding box searches for rectangular geographic areas
- Radius-based circular searches around specific points
Perfect For:
- Location discovery within specific neighborhoods or districts
- Delivery and service area applications
- Tourism and local business discovery
Common Search Parameters
All search services share a consistent parameter structure that allows for fine-tuning results based on your application’s requirements:
const results = await search({ query: 'restaurants', position: [longitude, latitude], // Reference point for relevance limit: 10, // Maximum results (1-100) radius: 5000, // Search radius in meters categorySet: ['RESTAURANT'], // Filter by POI categories countrySet: ['NL', 'DE'] // Restrict to specific countries});Parameter Details:
- query: The search term or natural language query
- position: Geographic reference point for result ranking and proximity
- limit: Controls result quantity for performance optimization
- radius: Defines search area scope in meters
- categorySet: Filters results by predefined POI categories
- countrySet: Restricts results to specific ISO country codes
Working with Search Results
Search results follow a consistent GeoJSON structure that integrates seamlessly with mapping and visualization components:
const results = await search({ query: 'coffee', position: [4.9041, 52.3676]});
results.features.forEach(place => { console.log(place.poi.name); // Business name console.log(place.address.freeformAddress); // Complete address console.log(place.position); // [longitude, latitude] console.log(place.categories); // POI categories});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});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
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 pagination for 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 Parking - Specialized search example for finding parking locations
Related Services
- Geocoding - Convert search result addresses to precise coordinates for enhanced accuracy
- Reverse Geocoding - Get address information for search result coordinates