Skip to content

Instantly share code, notes, and snippets.

@kmesiab
Created April 19, 2022 22:58
Show Gist options
  • Save kmesiab/5d88966384a7d6121ec0354b977bbb56 to your computer and use it in GitHub Desktop.
Save kmesiab/5d88966384a7d6121ec0354b977bbb56 to your computer and use it in GitHub Desktop.
<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