feature/geolocation implemented

This commit is contained in:
Joaquin committed 2025-05-06 13:38:00 -07:00
1 parent 6d91934229
commit 83be006a83
3 files changed
+39

No files matched your search

+24
View File
@@ -0,0 +1,24 @@
function getLocation() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(success, error);
}
}
function success(position) {
const { latitude, longitude } = position.coords;
fetch("api/location" , {
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify({ latitude, longitude })
}).then(res => res.json())
.then(data => {
console.log(data.results[0].formatted_address);
})
}
function error(err) {
console.error("Geolocation error: ", err);
}