/** * Geolocation position interface */ export type GeolocationPosition = { latitude: number; longitude: number; accuracy: number; altitude: number | null; altitudeAccuracy: number | null; heading: number | null; speed: number | null; timestamp: number; }; /** * Geolocation error interface */ export type GeolocationError = { code: number; message: string; permissionDenied: 1; positionUnavailable: 2; timeout: 3; }; /** * Hook options */ export type UseGeolocationOptions = { enableHighAccuracy?: boolean; timeout?: number; maximumAge?: number; watch?: boolean; }; /** * Hook return value */ export type UseGeolocationReturn = { position: GeolocationPosition | null; loading: boolean; error: GeolocationError | null; getCurrentPosition: () => void; watchId: number | null; }; /** * Geolocation state */ export type GeolocationState = { loading: boolean; position: GeolocationPosition | null; error: GeolocationError | null; }; /** * Hook that tracks geo location state of user's device * * @param options - Geolocation options * @returns Geolocation state and control functions * * @example * ```tsx * const { loading, position, error, getCurrentPosition } = useGeolocation({ * enableHighAccuracy: true, * timeout: 10000, * maximumAge: 300000, * }); * * return ( *
Loading location...
} * {error &&Error: {error.message}
} * {position && ( ** Latitude: {position.latitude}, Longitude: {position.longitude} *
* )} * *