From e0a9b8b82c731cb667951aabb213f63a063722e2 Mon Sep 17 00:00:00 2001 From: root Date: Tue, 15 Jul 2025 11:21:38 +0200 Subject: [PATCH] =?UTF-8?q?dodano=20lokalizacje=20u=C5=BCytkownika?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- templates/index.html | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/templates/index.html b/templates/index.html index 2be6883..365e570 100644 --- a/templates/index.html +++ b/templates/index.html @@ -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(); +}); + +