Skip to content

useGeolocation

Category
Export Size
545 B
Last Changed
5 days ago

Reactive Geolocation API

Demo

Usage

tsx
import { 
useGeolocation
} from '@reause/core'
const {
coords
,
locatedAt
,
error
,
resume
,
pause
} =
useGeolocation
()
StateTypeDescription
coordsCoordinatesinformation about the position retrieved like the latitude and longitude
locatedAtnumber | nullThe time of the last geolocation call (epoch ms)
errorGeolocationPositionError | nullThe GeolocationPositionError in case the geolocation API fails.
resumefunctionControl function to resume updating geolocation
pausefunctionControl 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

Source

Source · Demo · VueUse

Contributors

hairyf

Changelog

v0.1.0 on
48d87 - fix(core): resolve useGeolocation audit findings (#580)

Released under the MIT License. v0.1.8