Created
May 9, 2023 16:09
-
-
Save sanatem/4ac7bfad28472f4ea44a2b5377aa2fd0 to your computer and use it in GitHub Desktop.
Geolocation React example
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
const [coords, setCoords] = useState({}); | |
useEffect(() => { | |
navigator.geolocation.getCurrentPosition( | |
position => { | |
const { latitude, longitude } = position.coords; | |
setCoords({ lat: latitude, lng: longitude }); | |
}, | |
error => { | |
console.log(error.message); | |
}, | |
{ enableHighAccuracy: true, timeout: 20000, maximumAge: 1000 } | |
); | |
}, []); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment