Skip to content

Instantly share code, notes, and snippets.

@alexfinnarn
Last active February 13, 2018 18:41
Show Gist options
  • Save alexfinnarn/dc952be8c411c57487c997a6ba4846a7 to your computer and use it in GitHub Desktop.
Save alexfinnarn/dc952be8c411c57487c997a6ba4846a7 to your computer and use it in GitHub Desktop.
Get Location Once Mounted
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