Skip to content

Instantly share code, notes, and snippets.

@andygup
Created February 5, 2019 22:43
Show Gist options
  • Save andygup/34549cfcb2ba39a67dfb806a1ca595b7 to your computer and use it in GitHub Desktop.
Save andygup/34549cfcb2ba39a67dfb806a1ca595b7 to your computer and use it in GitHub Desktop.
Validate if JavaScript Geolocation API is available or not
if ("geolocation" in navigator) {
navigator.geolocation.getCurrentPosition(({ coords }) => {
const { latitude, longitude } = coords;
console.log(latitude + ", " + longitude);
}, error => {
console.error(error);
});
} else {
// handle the error
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment