Try browser geolocation for location with London fallback

This commit is contained in:
Richard Zink committed 2026-10-07 14:30:42 +02:00
1 parent 223d1a3d74
commit fd73c3ec1c
1 file changed
+30 -2
+30 -2
View File
@@ -1625,8 +1625,34 @@ window.weatherThemes = {
}
// ============ Weather ============
var WEATHER_LAT = (window.CONFIG && window.CONFIG.location && window.CONFIG.location.lat) || 48.5667;
var WEATHER_LON = (window.CONFIG && window.CONFIG.location && window.CONFIG.location.lon) || 13.4319;
// Default location: London, UK
var DEFAULT_LAT = 51.5074;
var DEFAULT_LON = -0.1278;
var WEATHER_LAT = (window.CONFIG && window.CONFIG.location && window.CONFIG.location.lat) || DEFAULT_LAT;
var WEATHER_LON = (window.CONFIG && window.CONFIG.location && window.CONFIG.location.lon) || DEFAULT_LON;
// Try browser geolocation if no config location set
function initBrowserGeolocation() {
if (window.CONFIG && window.CONFIG.location && window.CONFIG.location.lat) return;
if (!navigator.geolocation) return;
navigator.geolocation.getCurrentPosition(
function(pos) {
WEATHER_LAT = pos.coords.latitude;
WEATHER_LON = pos.coords.longitude;
window.CONFIG.location = { lat: WEATHER_LAT, lon: WEATHER_LON };
// Reload weather with new coordinates
if (typeof fetchWeather === 'function') fetchWeather();
},
function() { /* ignored - keep default */ },
{ timeout: 10000 }
);
}
// Get timezone offset based on user's local time
function getTimezoneOffsetMinutes() {
return new Date().getTimezoneOffset();
}
var weatherData = null;
var WMO_ICONS = {
@@ -1819,6 +1845,8 @@ window.weatherThemes = {
if (debugEl && !(window.CONFIG && window.CONFIG.debug)) {
debugEl.style.display = 'none';
}
// Try browser geolocation if no explicit location configured
initBrowserGeolocation();
animate();
tick();