@sv-use/core
Version:
A collection of Svelte 5 utilities.
42 lines (41 loc) • 1.63 kB
TypeScript
interface GetGeolocationOptions extends Partial<PositionOptions> {
/**
* Whether to auto-cleanup the geolocation service or not.
*
* If set to `true`, it must run in the component initialization lifecycle.
* @default true
*/
autoCleanup?: boolean;
/**
* Whether to start the geolocation service on creation or not.
* @default true
*/
immediate?: boolean;
}
type GetGeolocationReturn = {
/** Whether the Geolocation API is supported or not. */
readonly isSupported: boolean;
/** The position and altitude of the device on Earth, as well as the accuracy with which these properties are calculated. */
readonly coords: Omit<GeolocationCoordinates, 'toJSON'>;
readonly timestamp: number;
/** The reason of an error occurring when using the geolocating device. */
readonly error: GeolocationPositionError | null;
/** Resumes the geolocation service. */
resume: () => void;
/** Pauses the geolocation service. Can also be used to cleanup the geolocation service. */
pause: () => void;
/**
* Cleans up the geolocation service.
* @note Alias for `pause`.
*/
cleanup: () => void;
};
/**
* It allows the user to provide their location to web applications if they so desire.
*
* For privacy reasons, the user is asked for permission to report location information.
* @param options Additional options to customize the behavior.
* @see https://svelte-librarian.github.io/sv-use/docs/core/get-geolocation
*/
export declare function getGeolocation(options?: GetGeolocationOptions): GetGeolocationReturn;
export {};