Last active
February 13, 2018 18:41
-
-
Save alexfinnarn/dc952be8c411c57487c997a6ba4846a7 to your computer and use it in GitHub Desktop.
Get Location Once Mounted
This file contains 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() { | |
let that = this; | |
var options = { | |
// enableHighAccuracy: true, | |
timeout: 8000, | |
maximumAge: 0 | |
}; | |
function success(pos) { | |
const crd = pos.coords; | |
const lat = crd.latitude; | |
const long = crd.longitude; | |
const accuracy = crd.accuracy; | |
console.log('Your current position is:'); | |
console.log(`Latitude : ${lat}`); | |
console.log(`Longitude: ${long}`); | |
console.log(`More or less ${accuracy} meters.`); | |
// Store user location to be used later. | |
that.userLocation = crd; | |
that.mapLat = lat; | |
that.mapLong = long; | |
// Take map off of loading mode. | |
that.loading = false; | |
// Add readable guess to user's location. | |
that.geocodeLocation(lat, long, that); | |
}; | |
function error(err) { | |
console.warn(`ERROR(${err.code}): ${err.message}`); | |
}; | |
navigator.geolocation.getCurrentPosition(success, error, options); | |
}, |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment