useGeolocation

Hook

Wraps the Geolocation API with a React-friendly interface. Does not read location until you call getCurrentPosition() or startWatching() — the browser permission prompt appears only when one of those runs. Options are passed through to the underlying Geolocation API.

core/use-geolocation

Installation

1 · Add registry to components.json

2 · Install component

Examples

Current position

Requests the device location and displays coordinates.

API Reference

PropTypeDescription
options
GeolocationOptionsPassed to navigator.geolocation.getCurrentPosition / watchPosition.
(returns) getCurrentPosition
() => voidCall when you want a one-shot fix (triggers permission prompt when needed).
(returns) startWatching / stopWatching
() => voidContinuous updates via watchPosition / clearWatch.
(returns) coords
GeolocationCoordinates | nullPosition coordinates once available.
(returns) loading
booleanTrue while fetching position.
(returns) error
GeolocationPositionError | nullError if permission denied or unavailable.