<html>
<body>
<p>Click the button to get your coordinates.</p>
<button onclick="getLocation()">Click</button>
<p id="location"></p>
<script>
var a = document.getElementById("location");
function getLocation() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(showPosition);
} else {
a.innerHTML = "Geolocation is not supported by this browser.";
}
}
function showPosition(position) {
a.innerHTML = "Latitude: " + position.coords.latitude +
"<br><br>Longitude: " + position.coords.longitude;
}
</script>
</body>
</html>