useGeolocation
HookWraps 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-geolocationInstallation
1 · Add registry to components.json
2 · Install component
Examples
Current position
Requests the device location and displays coordinates.
API Reference
| Prop | Type | Default | Description |
|---|---|---|---|
options | GeolocationOptions | — | Passed to navigator.geolocation.getCurrentPosition / watchPosition. |
(returns) getCurrentPosition | () => void | — | Call when you want a one-shot fix (triggers permission prompt when needed). |
(returns) startWatching / stopWatching | () => void | — | Continuous updates via watchPosition / clearWatch. |
(returns) coords | GeolocationCoordinates | null | — | Position coordinates once available. |
(returns) loading | boolean | — | True while fetching position. |
(returns) error | GeolocationPositionError | null | — | Error if permission denied or unavailable. |