dodano lokalizacje użytkownika
This commit is contained in:
@ -318,7 +318,41 @@ Czas pomiaru: ${current.time ? new Date(current.time).toLocaleString() : 'brak d
|
||||
}
|
||||
});
|
||||
}
|
||||
function getUserLocation() {
|
||||
if (navigator.geolocation) {
|
||||
updateResult("Pobieranie Twojej lokalizacji...");
|
||||
navigator.geolocation.getCurrentPosition(
|
||||
async (position) => {
|
||||
const lat = position.coords.latitude;
|
||||
const lon = position.coords.longitude;
|
||||
|
||||
setMarker(lat, lon, "Ładowanie nazwy...");
|
||||
map.setView([lat, lon], 10);
|
||||
try {
|
||||
const placeName = await fetchPlaceName(lat, lon);
|
||||
currentPlaceName = placeName;
|
||||
setMarker(lat, lon, placeName);
|
||||
updateResult("Ładowanie pogody...");
|
||||
await fetchWeather(lat, lon);
|
||||
} catch (err) {
|
||||
updateResult("Błąd lokalizacji: " + err.message);
|
||||
}
|
||||
},
|
||||
(error) => {
|
||||
updateResult("Nie udało się uzyskać lokalizacji: " + error.message);
|
||||
}
|
||||
);
|
||||
} else {
|
||||
updateResult("Geolokalizacja nie jest obsługiwana w tej przeglądarce.");
|
||||
}
|
||||
}
|
||||
|
||||
window.addEventListener('load', () => {
|
||||
getUserLocation();
|
||||
});
|
||||
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user