x
 
1
<!DOCTYPE html>
2
<html>
3
<body>
4
5
<p>Click the button to get your coordinates.</p>
6
<button onclick="getLocation()">Click</button>
7
8
<p id="location"></p>
9
10
<script>
11
var a = document.getElementById("location");
12
13
function getLocation() {
14
  if (navigator.geolocation) {
15
    navigator.geolocation.getCurrentPosition(showPosition);
16
  } else { 
17
    a.innerHTML = "Geolocation is not supported by this browser.";
18
  }
19
}
20
21
function showPosition(position) {
22
  a.innerHTML = "Latitude: " + position.coords.latitude + 
23
  "<br><br>Longitude: " + position.coords.longitude;
24
}
25
</script>
26
27
</body>
28
</html>