useGeolocation
Hook that returns the current geolocation
browser
medium
test coverage
Last changed: 7 months ago
TIP
This hook uses navigator.geolocation browser api to provide enhanced functionality. Make sure to check for compatibility with different browsers when using this api
Installation
Library
CLI
Manual
typescript
import { useGeolocation } from '@siberiacancode/reactuse';Usage
typescript
const { loading, error, timestamp, accuracy, latitude, longitude, altitude, altitudeAccuracy, heading, speed } = useGeolocation();Demo
Api
Parameters
| Name | Type | Default | Note |
|---|---|---|---|
| params.enableHighAccuracy? | boolean | - | Enable high accuracy |
| params.maximumAge? | number | - | Maximum age |
| params.timeout? | number | - | Timeout |
Returns
UseGeolocationReturn
Type declaration
typescript
export interface UseGeolocationReturn {
/** The accuracy of the last position update */
accuracy: number | null;
/** The altitude of the last position update */
altitude: number | null;
/** The altitude accuracy of the last position update */
altitudeAccuracy: number | null;
/** The error of the last position update */
error: GeolocationPositionError | null;
/** The heading of the last position update */
heading: number | null;
/** The latitude of the last position update */
latitude: number | null;
/** The loading state */
loading: boolean;
/** The longitude of the last position update */
longitude: number | null;
/** The speed of the last position update */
speed: number | null;
/** The timestamp of the last position update */
timestamp: number | null;
}
export type UseGeolocationParams = PositionOptions;Source
Source • DemoContributors
D
Z