Created
September 12, 2016 16:23
-
-
Save thebiltheory/fdaf498e9fc2d85384357b4f0150ce47 to your computer and use it in GitHub Desktop.
Get the browser geolocation
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
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