Skip to content

Instantly share code, notes, and snippets.

@AppMkrATL
Forked from codeguy/get-current-location.js
Created September 12, 2018 04:35
Show Gist options
  • Save AppMkrATL/08c0c62d9c58868920f8dd5fdc1fe29c to your computer and use it in GitHub Desktop.
Save AppMkrATL/08c0c62d9c58868920f8dd5fdc1fe29c to your computer and use it in GitHub Desktop.
Get user's current gelocation with HTML Geolocation API
if ('geolocation' in navigator) {
console.log('Supports HTML geolocation API');
(function () {
var onSuccess = function (location) {
console.log('User location', location);
var userLat = location.coords.latitude,
userLon = location .coords.longitude;
},
onError = function (code, message) {
console.log('Gelocation error', code, message);
};
navigator.geolocation.getCurrentPosition(onSuccess, onError);
})();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment