Get Location

 avatar
unknown
javascript
3 years ago
608 B
4
Indexable
<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>
Editor is loading...