diff --git a/geo.js b/geo.js new file mode 100644 index 0000000..95e0f0e --- /dev/null +++ b/geo.js @@ -0,0 +1,14 @@ +const myElement = document.getElementById("demo"); + +function getLocation() { + if (navigator.geolocation) { + navigator.geolocation.getCurrentPosition(showPosition); + } else { + myElement.innerHTML = "Geolocation is not supported by this browser."; + } +} + +function showPosition(position) { + myElement.innerHTML = "Latitude: " + position.coords.latitude + + "
Longitude: " + position.coords.longitude; +}