Created
September 9, 2019 13:19
-
-
Save onejohi/e8e472e57a081a66e606400a8f52a343 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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