# Geolocation

The Geolocation API 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.

# State

The useGeolocation function exposes the following reactive state:

import { useGeolocation } from 'vue-use-web';

const { coords, locatedAt, error } = useGeolocation();
State Type Description
coords Coordinates information about the position retrieved like the latitude and longitude
locatedAt Date The time of the last geolocation call
error string An error message in case geolocation API fails.

# Config

useGeolocation function takes PositionOptions object as an optional parameter.

import { useGeolocation } from 'vue-use-web';

const { coords } = useGeolocation({
  enableHighAccuracy: true,
  maximumAge: 30000,
  timeout: 27000
});

# Example

<template>
  <div>
    <div>User position is: {{ coords.longitude }} {{ coords.latitude }}</div>
    <div>Last updated: {{ locatedAt }}</div>
  </div>
</template>

<script>
import { useGeolocation } from 'vue-use-web';

export default {
  setup() {
    const { coords, locatedAt } = useGeolocation();

    return { coords, locatedAt };
  }
};
</script>