Googlemap

Google Map Service

Description

  • internalServerUrl:
    • Static property used to prefix all Google Maps API requests: "/api/google-maps"

fetchPlaceSuggestions(input: string, countries: string[] = ["nl"])

  • Description: Fetches city-level autocomplete suggestions based on user input.
  • Parameters:
    • input (string): The user-typed search text.
    • countries (string, default: ["nl"]): List of country codes for restricting suggestions.
  • Behaviour:
    • Converts the country list into a components string for Google Maps API.
    • Uses the types: "(cities)" filter to limit results to city-level locations.
  • Returns: A Promise resolving to google.maps.places.AutocompleteResponse.

fetchPlaceDetails(placeId: string): Promise<google.maps.places.PlaceResult>

  • Description: Retrieves detailed place information (like latitude and longitude) for a given placeId.
  • Parameters:
    • placeId (string): The unique Google Maps identifier for a location.
  • Error handling:
    • Throws an error if the API response status is not "OK".
  • Returns: A Promise resolving to google.maps.places.PlaceResult.

fetchTextSearchResults(query: string): Promise<google.maps.places.PlaceResult>

  • Description: Performs a text-based location search and returns the most relevant result.
  • Parameters:
    • query (string): Text input describing a place (e.g., city or landmark name).
  • Error handling:
    • Throws an error if no results are returned or if something goes wrong in the API call.
  • Returns: A Promise resolving to the most relevant PlaceResult.

Points to be Remember

  • All methods use the $fetch utility to interact with server-side proxy endpoints (/api/google-maps/...) that wrap official Google Maps API calls.
  • Error messages are descriptive and provide clear guidance for debugging.
  • Suitable for server-safe, restricted usage (e.g., hiding API keys).

Copyright © 2026