@cercalia/sdk
    Preparing search index...

    Class ReverseGeocodingService

    Service for reverse geocoding operations using Cercalia API.

    Converts geographic coordinates into address information and administrative hierarchy. Also supports timezone lookup and special category queries.

    Hierarchy (View Summary)

    Index

    Constructors

    Properties

    Configuration for the Cercalia API connection.

    Methods

    • Gets regions/municipalities that intersect a polygon.

      Parameters

      • wkt: string

        Polygon geometry in WKT format.

      • level: "ct" | "mun" | "subreg" | "reg" = 'mun'

        Administrative level to return ('ct', 'mun', 'subreg', 'reg').

      Returns Promise<ReverseGeocodeResult[]>

      Promise resolving to array of administrative regions in the polygon.

      const polygon = 'POLYGON((2.0 41.0, 2.5 41.0, 2.5 41.5, 2.0 41.5, 2.0 41.0))';
      const municipalities = await service.getIntersectingRegions(polygon, 'mun');
    • Gets timezone information for a coordinate.

      Parameters

      Returns Promise<TimezoneResult | null>

      Promise resolving to timezone information or null if not found.

      const tz = await service.getTimezone(
      { lat: 41.3851, lng: 2.1734 },
      { dateTime: '2024-01-15T14:30:00Z' }
      );

      if (tz) {
      logger.info(tz.id); // e.g., "Europe/Madrid"
      logger.info(tz.utcOffset); // e.g., 3600
      }
    • 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'
      );
    • Reverse geocodes a single coordinate to get address information.

      Parameters

      Returns Promise<ReverseGeocodeResult | null>

      Promise resolving to reverse geocoding result or null if no match.

      const service = new ReverseGeocodingService(config);
      const result = await service.reverseGeocode(
      { lat: 41.3851, lng: 2.1734 }
      );

      if (result) {
      logger.info(result.ge.street); // e.g., "Carrer de Provença"
      logger.info(result.ge.municipality); // e.g., "Barcelona"
      }
    • Reverse geocodes multiple coordinates in a single request.

      Parameters

      Returns Promise<ReverseGeocodeResult[]>

      Promise resolving to array of reverse geocoding results.

      Error if more than 100 coordinates are provided.

      const results = await service.reverseGeocodeBatch([
      { lat: 41.3851, lng: 2.1734 },
      { lat: 40.4168, lng: -3.7038 }
      ]);