<html>
<head>
<title>
GEO
</title>
</head>
<body>
<button>GET LOCATION</button>
</body>
<script>
const button = document.querySelector("button");
button.addEventListener("click", (e) => {
navigator.geolocation.getCurrentPosition(position => {
const { latitude, longitude } = position.coords;
console.log(`https://nominatim.openstreetmap.org/reverse?format=jsonv2&lat=${latitude}&lon=${longitude}`)
const url = `https://nominatim.openstreetmap.org/reverse?format=jsonv2&lat=${latitude}&lon=${longitude}`;
fetch(url)
.then(response => response.json())
.then((data) => { console.log(data) })
.catch((error) => {console.log(error)});
})
})
</script>
</html>
No comments:
Post a Comment