diff --git a/static/js/history.js b/static/js/history.js index f2b3fcd..e7c1677 100644 --- a/static/js/history.js +++ b/static/js/history.js @@ -31,19 +31,21 @@ const key = `${lat.toFixed(3)},${lon.toFixed(3)}`; if (key === _lastGeoKey) return; _lastGeoKey = key; + const fallback = `${lat.toFixed(5)}, ${lon.toFixed(5)}`; fetch(`https://nominatim.openstreetmap.org/reverse?format=jsonv2&lat=${lat}&lon=${lon}`, { - headers: { 'Accept-Language': 'en' } + headers: { 'Accept-Language': 'en' }, + signal: AbortSignal.timeout(5000), }) .then(r => r.ok ? r.json() : null) .then(data => { - if (!data) return; + if (!data) { replayLocation.textContent = fallback; return; } const a = data.address || {}; const road = a.road || a.hamlet || a.village || a.suburb || ''; const city = a.city || a.town || a.village || a.municipality || ''; replayLocation.textContent = [road, city].filter(Boolean).join(', ') - || data.display_name?.split(',').slice(0, 2).join(',') || ''; + || data.display_name?.split(',').slice(0, 2).join(',') || fallback; }) - .catch(() => {}); + .catch(() => { replayLocation.textContent = fallback; }); } function scheduleGeocode(lat, lon) { diff --git a/static/js/yaris.js b/static/js/yaris.js index 7fa77c8..2459f3c 100644 --- a/static/js/yaris.js +++ b/static/js/yaris.js @@ -196,19 +196,22 @@ _recenterBtn.addEventListener('click', function () { }); function reverseGeocode(lat, lon) { + const fallback = `${lat.toFixed(5)}, ${lon.toFixed(5)}`; + const el = document.getElementById('gps-location-name'); fetch(`https://nominatim.openstreetmap.org/reverse?format=jsonv2&lat=${lat}&lon=${lon}`, { - headers: { 'Accept-Language': 'en' } + headers: { 'Accept-Language': 'en' }, + signal: AbortSignal.timeout(5000), }) .then(r => r.ok ? r.json() : null) .then(data => { - if (!data) return; + if (!data) { el.textContent = fallback; return; } const a = data.address || {}; const name = a.road || a.hamlet || a.village || a.suburb || ''; const city = a.city || a.town || a.village || a.municipality || ''; const label = [name, city].filter(Boolean).join(', '); - document.getElementById('gps-location-name').textContent = label || data.display_name?.split(',').slice(0,2).join(',') || ''; + el.textContent = label || data.display_name?.split(',').slice(0, 2).join(',') || fallback; }) - .catch(() => {}); + .catch(() => { el.textContent = fallback; }); } socket.on('gps_location', function(data) {