Skip to content

Instantly share code, notes, and snippets.

@onejohi
Created September 9, 2019 13:19
Show Gist options
  • Save onejohi/e8e472e57a081a66e606400a8f52a343 to your computer and use it in GitHub Desktop.
Save onejohi/e8e472e57a081a66e606400a8f52a343 to your computer and use it in GitHub Desktop.
mounted() {
// call methods when component is done "mounting" :wink:
this.getUserLocation();
this.trackUserLocation();
},
methods: {
getUserLocation() {
// get user position
window.navigator.geolocation.getCurrentPosition((position) => {
const { latitude, longitude } = position.coords;
console.log(`Your user is positioned at Lat: ${latitude}, Lng: ${longitude}`)
});
}
trackUserLocation() {
// track/follow user position
window.navigator.geolocation.watchPosition(pos => {
const { latitude, longitude } = pos.coords;
console.log(`Your user is positioned at Lat: ${latitude}, Lng: ${longitude}`);
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment