Appearance
useGeolocation
Reactive Geolocation API
Demo
Usage
tsx
import { useGeolocation } from '@reause/core'
const { coords, locatedAt, error, resume, pause } = useGeolocation()| State | Type | Description |
|---|---|---|
| coords | Coordinates | information about the position retrieved like the latitude and longitude |
| locatedAt | number | null | The time of the last geolocation call (epoch ms) |
| error | GeolocationPositionError | null | The GeolocationPositionError in case the geolocation API fails. |
| resume | function | Control function to resume updating geolocation |
| pause | function | Control function to pause updating geolocation |
Config
useGeolocation function takes PositionOptions object as an optional parameter.
Type Declarations
ts
export interface UseGeolocationOptions extends Partial<PositionOptions>, ConfigurableNavigator {
immediate?: boolean;
}
export interface UseGeolocationReturn {
isSupported: boolean;
coords: Omit<GeolocationPosition['coords'], 'toJSON'>;
locatedAt: number | null;
error: GeolocationPositionError | null;
resume: () => void;
pause: () => void;
}
interface ConfigurableNavigator {
navigator?: Navigator;
}
export function useGeolocation(options?: UseGeolocationOptions): UseGeolocationReturn