Skip to content

Instantly share code, notes, and snippets.

@thebiltheory
Created September 12, 2016 16:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thebiltheory/fdaf498e9fc2d85384357b4f0150ce47 to your computer and use it in GitHub Desktop.
Save thebiltheory/fdaf498e9fc2d85384357b4f0150ce47 to your computer and use it in GitHub Desktop.
Get the browser geolocation
var getCoords = function (options) {
return new Promise(function (resolve, reject) {
navigator.geolocation.getCurrentPosition(resolve, reject, options);
});
}
var geo_options = {
enableHighAccuracy: true,
maximumAge : 30000,
timeout : 27000
};
getCoords(geo_options)
.then((position) => {
console.log("With Geo Options");
console.log(position.coords.latitude, position.coords.longitude);
})
.catch((err) => {
console.error("Something is wrong: ",err.message);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment