Skip to content
View source

Geolocate Control

VControlGeolocate centers the map on the visitor's location using the browser Geolocation API. It emits locate with the position and error if permission is denied. Set track-user-location to follow movement.

Click the ◎ button to locate yourself.

GeolocateControl.vue
<script setup lang="ts">
  import { VMap, VControlGeolocate } from '@geoql/v-mapkit';

  function onLocate(position) {
    console.log(position.coords.latitude, position.coords.longitude);
  }
</script>

<template>
  <VMap :access-token="token">
    <VControlGeolocate
      position="top-right"
      :track-user-location="false"
      @locate="onLocate"
      @error="(e) => console.warn(e)"
    />
  </VMap>
</template>