Skip to content

Instantly share code, notes, and snippets.

@codebucks27
Last active November 24, 2020 07:59
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 codebucks27/70edb9c9e5f7951b2bbf80dc3d6d8ae7 to your computer and use it in GitHub Desktop.
Save codebucks27/70edb9c9e5f7951b2bbf80dc3d6d8ae7 to your computer and use it in GitHub Desktop.
Medium Article GeoLocation -- 1
import React, { Component } from "react";
export default class GeoLocation extends Component {
componentDidMount() {
if (navigator.geolocation) {
navigator.permissions
.query({ name: "geolocation" })
.then(function (result) {
if (result.state === "granted") {
console.log(result.state);
//If granted then you can directly call your function here
} else if (result.state === "prompt") {
console.log(result.state);
} else if (result.state === "denied") {
//If denied then you have to show instructions to enable location
}
result.onchange = function () {
console.log(result.state);
};
});
} else {
alert("Sorry Not available!");
}
}
render() {
return (
<div>
<h2>GeoLocation</h2>
</div>
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment