From f099ce8093fa82717874badcd2d89e19422616d4 Mon Sep 17 00:00:00 2001 From: sebastjanartic <45803536-sebastjanartic@users.noreply.replit.com> Date: Mon, 2 Mar 2026 17:26:23 +0000 Subject: [PATCH] Improve weather widget accuracy using browser geolocation Update the weather widget to prioritize browser geolocation for more precise location detection, falling back to IP-based geolocation if denied. Replit-Commit-Author: Agent Replit-Commit-Session-Id: 517dfa7b-26ac-463d-a6e1-a58c6df97188 Replit-Commit-Checkpoint-Type: full_checkpoint Replit-Commit-Event-Id: 16c59ca7-47f2-4f61-8db4-36a7181ab46b Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/f209e72a-0939-48fa-84fc-57854de71967/517dfa7b-26ac-463d-a6e1-a58c6df97188/nFw7xof Replit-Helium-Checkpoint-Created: true --- client/src/components/weather-widget.tsx | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/client/src/components/weather-widget.tsx b/client/src/components/weather-widget.tsx index b8101f9..3a2b612 100644 --- a/client/src/components/weather-widget.tsx +++ b/client/src/components/weather-widget.tsx @@ -176,7 +176,24 @@ export function SidebarWeatherWidget() { } } - getLocationByIP(); + if (navigator.geolocation) { + navigator.geolocation.getCurrentPosition( + async (pos) => { + try { + const res = await fetch(`https://nominatim.openstreetmap.org/reverse?lat=${pos.coords.latitude}&lon=${pos.coords.longitude}&format=json&accept-language=de`); + const geo = await res.json(); + const city = geo.address?.city || geo.address?.town || geo.address?.village || "Unbekannt"; + fetchWeather(pos.coords.latitude, pos.coords.longitude, city); + } catch { + fetchWeather(pos.coords.latitude, pos.coords.longitude, "Unbekannt"); + } + }, + () => { getLocationByIP(); }, + { timeout: 5000 } + ); + } else { + getLocationByIP(); + } }, []); const [forecast, setForecast] = useState<{ day: string; high: number; low: number; code: number }[]>([]);