fix(map): show raw coords as fallback when geocode fails or times out

- 5s timeout on Nominatim fetch (AbortSignal.timeout)
- On network error, non-200, or empty result: show 'lat, lon' (5 decimal places)
- Applies to both dashboard live location and history scrubber

Co-authored-by: Copilot <[email protected]>
This commit is contained in:
Mathieu Moran
2026-08-10 02:46:33 -04:00
co-authored by Copilot
parent 548808fd83
commit 91d475fd24
2 changed files with 13 additions and 8 deletions
+6 -4
View File
@@ -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) {
+7 -4
View File
@@ -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) {