1//Click the button to get your coordinates
2<button onclick="getLocation()">Try It</button>
3<script>
4function getLocation() {
5 if (navigator.geolocation) {
6 navigator.geolocation.getCurrentPosition(showPosition);
7 } else {
8 x.innerHTML = "Geolocation is not supported by this browser.";
9 }
10}
11function showPosition(position) {
12 x.innerHTML = "Latitude: " + position.coords.latitude +
13 "<br>Longitude: " + position.coords.longitude;
14}
15</script>
16