Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Apply VueUse composables in Vue 3/Nuxt projects to replace custom implementations with battle-tested utilities.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
references/useGeolocation.md
1---2category: Sensors3---45# useGeolocation67Reactive [Geolocation API](https://developer.mozilla.org/en-US/docs/Web/API/Geolocation_API). 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.89## Usage1011```ts12import { useGeolocation } from '@vueuse/core'1314const { coords, locatedAt, error, resume, pause } = useGeolocation()15```1617| State | Type | Description |18| --------- | ----------------------------------------------------------------------------- | ------------------------------------------------------------------------ |19| coords | [`Coordinates`](https://developer.mozilla.org/en-US/docs/Web/API/Coordinates) | information about the position retrieved like the latitude and longitude |20| locatedAt | `Date` | The time of the last geolocation call |21| error | `string` | An error message in case geolocation API fails. |22| resume | `function` | Control function to resume updating geolocation |23| pause | `function` | Control function to pause updating geolocation |2425## Config2627`useGeolocation` function takes [PositionOptions](https://developer.mozilla.org/en-US/docs/Web/API/PositionOptions) object as an optional parameter.2829## Component Usage3031```vue32<template>33<UseGeolocation v-slot="{ coords: { latitude, longitude } }">34Latitude: {{ latitude }}35Longitude: {{ longitude }}36</UseGeolocation>37</template>38```3940## Type Declarations4142```ts43export interface UseGeolocationOptions44extends Partial<PositionOptions>, ConfigurableNavigator {45immediate?: boolean46}47export interface UseGeolocationReturn extends Supportable {48coords: Ref<Omit<GeolocationPosition["coords"], "toJSON">>49locatedAt: ShallowRef<number | null>50error: ShallowRef<GeolocationPositionError | null>51resume: () => void52pause: () => void53}54/**55* Reactive Geolocation API.56*57* @see https://vueuse.org/useGeolocation58* @param options59*/60export declare function useGeolocation(61options?: UseGeolocationOptions,62): UseGeolocationReturn63```64