getGeolocation
Category Sensors
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.
Demo
{ "isSupported": false, "coords": { "accuracy": 0, "latitude": null, "longitude": null, "altitude": null, "altitudeAccuracy": null, "heading": null, "speed": null }, "timestamp": 0, "error": null }
Usage
Type definitions
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/sensors/get-geolocation
*/
export declare function getGeolocation(options?: GetGeolocationOptions): GetGeolocationReturn;
export {};