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 }[]>([]);