Created
April 19, 2022 22:58
-
-
Save kmesiab/5d88966384a7d6121ec0354b977bbb56 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
<html> | |
<body> | |
<p>Extract Latitude & Longitude</p> | |
<p> | |
<p><ul>I think you're about right here:</ul></p> | |
Lat: <span id="latitude"></span> | |
Lon: <span id="longitude"></span> | |
</p> | |
<p><button id="get-location">Find Me!</button> | |
</body> | |
<script> | |
let button = document.getElementById("get-location"); | |
let latText = document.getElementById("latitude"); | |
let longText = document.getElementById("longitude"); | |
console.log(button); | |
button.addEventListener("click", function() { | |
navigator.geolocation.getCurrentPosition(function(position) { | |
let lat = position.coords.latitude; | |
let long = position.coords.longitude; | |
latText.innerText = lat.toFixed(2); | |
longText.innerText = long.toFixed(2); | |
}); | |
}); | |
</script> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment