-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
29 lines (27 loc) · 918 Bytes
/
Copy pathindex.html
File metadata and controls
29 lines (27 loc) · 918 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Get Current Address</title>
</head>
<body>
<button>Get Current Address</button>
<script>
const button = document.querySelector("button");
button.addEventListener("click", () => {
navigator.geolocation.getCurrentPosition((position) => {
const { latitude, longitude } = position.coords;
const url = `https://nominatim.openstreetmap.org/reverse?format=json&lat=${latitude}&lon=${longitude}`;
fetch(url)
.then((res) => res.json())
.then((data) => {
console.log(data.display_name);
console.table(data.address);
})
.catch(() => console.error("Error on fetching data."));
});
});
</script>
</body>
</html>