@cercalia/sdk
    Preparing search index...

    Class SuggestService

    SuggestService - Address and POI autocomplete using Cercalia Suggest API

    This service provides real-time autocomplete suggestions for addresses, streets, cities, and POIs. It's designed for typeahead search experiences.

    • Street suggestions: Autocomplete street names with house number availability
    • City suggestions: Find cities/localities by partial name
    • POI suggestions: Search points of interest with category filtering
    • Geocoding: Convert suggestions to precise coordinates
    const suggest = new SuggestService(config);

    // Basic address autocomplete
    const results = await suggest.search({ text: 'Provença 5' });

    // Filter by country and type
    const streets = await suggest.search({
    text: 'Gran Via',
    countryCode: 'ESP',
    geoType: 'st'
    });

    // Geocode a specific result
    const coords = await suggest.geocode({
    streetCode: results[0].street?.code,
    streetNumber: '589',
    cityCode: results[0].city?.code
    });

    Hierarchy (View Summary)

    Index

    Constructors

    Properties

    Configuration for the Cercalia API connection.

    Methods

    • Combined search and geocode - finds and geocodes the best match

      This is a convenience method that combines search and geocode in one call. Useful when you need coordinates directly from a text query.

      Parameters

      • text: string

        Address text to search

      • Optionaloptions: { countryCode?: string; streetNumber?: string }

        Optional filtering options

      Returns Promise<SuggestGeocodeResult | null>

      Geocoded result of the best match, or null if no results

      const location = await service.findAndGeocode('Provença 589, Barcelona');
      if (location) {
      logger.info(location.coord); // { lat: 41.41, lng: 2.18 }
      }
    • Geocode a suggestion to get precise coordinates

      After selecting a suggestion from search(), use this method to get the exact coordinates for the address. For streets, you can specify a house number to get the precise location.

      Parameters

      Returns Promise<SuggestGeocodeResult>

      Geocoded result with coordinates and full address

      Error if geocoding fails or no results found

      // First search for suggestions
      const suggestions = await service.search({ text: 'Provença 5' });

      // Then geocode the selected suggestion with specific number
      const location = await service.geocode({
      streetCode: suggestions[0].street?.code,
      streetNumber: '589',
      cityCode: suggestions[0].city?.code,
      countryCode: 'ESP'
      });

      logger.info(location.coord); // { lat: 41.41, lng: 2.18 }
    • Executes a generic request to the Cercalia API.

      Type Parameters

      • T

      Parameters

      • params: Record<string, string>

        Query parameters for the API request.

      • operationName: string = 'Cercalia Request'

        Human-readable name for logging and debugging.

      • OptionalbaseUrl: string

        Optional override for the base API URL.

      Returns Promise<T>

      A promise resolving to the parsed API response.

      Error with code '30006' when no results are found.

      Error for HTTP errors or invalid JSON responses.

      const response = await this.request<MyResponse>(
      { cmd: 'cand', adr: 'Gran Via 1' },
      'Geocoding'
      );
    • Search for address/POI suggestions based on partial text input

      Use this method for autocomplete/typeahead functionality. Returns suggestions ordered by relevance. Minimum 3 characters recommended for best results.

      Parameters

      Returns Promise<SuggestResult[]>

      Array of suggestions ordered by relevance

      // Search streets in Barcelona
      const results = await service.search({
      text: 'Diagonal',
      countryCode: 'ESP',
      geoType: 'st'
      });

      // Search POIs near a location
      const pois = await service.search({
      text: 'Restaurant',
      geoType: 'poi',
      center: { lat: 41.39, lng: 2.15 },
      radius: 5000
      });
    • Search for city/locality suggestions only

      Convenience method for city-only autocomplete.

      Parameters

      • text: string

        Search text

      • OptionalcountryCode: string

        Optional country code filter

      Returns Promise<SuggestResult[]>

      Array of city suggestions

      const cities = await service.searchCities('Barcel', 'ESP');
      
    • Search for POI suggestions only

      Convenience method for POI-only autocomplete.

      Parameters

      • text: string

        Search text

      • Optionaloptions: {
            center?: Coordinate;
            countryCode?: string;
            poiCategories?: string[];
            radius?: number;
        }

        Optional filtering options

      Returns Promise<SuggestResult[]>

      Array of POI suggestions

      // Search restaurants near Barcelona
      const pois = await service.searchPois('Restaurant', {
      center: { lat: 41.39, lng: 2.15 },
      radius: 5000,
      poiCategories: ['C014']
      });
    • Search for street suggestions only

      Convenience method for street-only autocomplete.

      Parameters

      • text: string

        Search text

      • OptionalcountryCode: string

        Optional country code filter

      Returns Promise<SuggestResult[]>

      Array of street suggestions

      const streets = await service.searchStreets('Gran Via', 'ESP');