Last active
November 24, 2020 07:59
-
-
Save codebucks27/70edb9c9e5f7951b2bbf80dc3d6d8ae7 to your computer and use it in GitHub Desktop.
Medium Article GeoLocation -- 1
This file contains 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
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