Get Location

mail@pastecode.io avatar
unknown
javascript
2 years ago
608 B
1
Indexable
Never
<template>
  <div>
    <p>Latitude: {{ latitude }}</p>
    <p>Longitude: {{ longitude }}</p>
  </div>
</template>

<script>
export default {
  data() {
    return {
      latitude: null,
      longitude: null
    }
  },
  created() {
    this.getLocation()
  },
  methods: {
    getLocation() {
      if (navigator.geolocation) {
        navigator.geolocation.getCurrentPosition(position => {
          this.latitude = position.coords.latitude
          this.longitude = position.coords.longitude
        })
      } else {
        // Geolocation is not supported by the browser
      }
    }
  }
}
</script>