Skip to main content

GeolocationApiService Actions

2 actions registered.

NameDeprecated
fetchGeolocation
fetchGeolocationData

GeolocationApiService:fetchGeolocation​

Package: @metamask/geolocation-controller

Returns the geolocation code. Serves from cache when the TTL has not expired, otherwise performs a network fetch. Concurrent callers are deduplicated to a single in-flight request.

Parameters:

NameDescription
optionsOptional fetch options.
options.bypassCacheWhen true, invalidates the TTL cache. If a request is already in-flight it will be reused (deduplication always applies).

Returns: An ISO 3166-2 location code (e.g. US, US-NY, CA-ON), or UNKNOWN_LOCATION when the API returns an empty or invalid body.

Handler signature:

(options?: FetchGeolocationOptions) => Promise<string>

GeolocationApiService:fetchGeolocationData​

Package: @metamask/geolocation-controller

Returns the country, region, and timezone for the current client. Serves from cache when the TTL has not expired, otherwise performs a network fetch. Concurrent callers are deduplicated to a single in-flight request.

Parameters:

NameDescription
optionsOptional fetch options.
options.bypassCacheWhen true, invalidates the TTL cache. If a request is already in-flight it will be reused (deduplication always applies).

Returns: The geolocation data, where each field is null when the API omits it or returns a value that fails validation.

Handler signature:

(options?: FetchGeolocationOptions) => Promise<GeolocationData>