Skip to content

Instantly share code, notes, and snippets.

@gh-o-st
Created November 11, 2020 17:50
Show Gist options
  • Select an option

  • Save gh-o-st/37571c69c951ac524f107df016d73b02 to your computer and use it in GitHub Desktop.

Select an option

Save gh-o-st/37571c69c951ac524f107df016d73b02 to your computer and use it in GitHub Desktop.
const testGeolocation = function() {
if ('permissions' in navigator) {
navigator.permissions.query({name:'geolocation'}).then(function(response) {
if (response.state == 'prompt') {
// do stuff for permission request
} else if (response.state == 'denied') {
// do stuff for permission denied
} else {
// do stuff for permission granted
}
}
} else {
navigator.geolocation.getCurrentPosition(
function(response) {
// do success things
},
function(response) {
if (response.code == response.PERMISSION_DENIED) {
// do stuff when they deny location
} else {
// do stuff when location fails for other reasons
}
},
{
maximumAge: Infinity,
timeout:0
}
);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment