diff --git a/static/js/history.js b/static/js/history.js index b50c714..c9f9c1b 100644 --- a/static/js/history.js +++ b/static/js/history.js @@ -32,10 +32,12 @@ if (key === _lastGeoKey) return; _lastGeoKey = key; const fallback = `${lat.toFixed(5)}, ${lon.toFixed(5)}`; - fetch(`/api/geocode?lat=${lat}&lon=${lon}`, { signal: AbortSignal.timeout(4000) }) - .then(r => r.ok ? r.json() : null) + const ctrl = new AbortController(); + const t = setTimeout(() => ctrl.abort(), 6000); + fetch(`/api/geocode?lat=${lat}&lon=${lon}`, { signal: ctrl.signal }) + .then(r => { clearTimeout(t); return r.ok ? r.json() : null; }) .then(data => { replayLocation.textContent = (data && data.label) ? data.label : fallback; }) - .catch(() => { replayLocation.textContent = fallback; }); + .catch(() => { clearTimeout(t); replayLocation.textContent = fallback; }); } function scheduleGeocode(lat, lon) { diff --git a/static/js/yaris.js b/static/js/yaris.js index f927558..43a4c4f 100644 --- a/static/js/yaris.js +++ b/static/js/yaris.js @@ -199,10 +199,12 @@ _recenterBtn.addEventListener('click', function () { function reverseGeocode(lat, lon) { const el = document.getElementById('gps-location-name'); const fallback = `${lat.toFixed(5)}, ${lon.toFixed(5)}`; - fetch(`/api/geocode?lat=${lat}&lon=${lon}`, { signal: AbortSignal.timeout(6000) }) - .then(r => r.ok ? r.json() : null) + const ctrl = new AbortController(); + const t = setTimeout(() => ctrl.abort(), 6000); + fetch(`/api/geocode?lat=${lat}&lon=${lon}`, { signal: ctrl.signal }) + .then(r => { clearTimeout(t); return r.ok ? r.json() : null; }) .then(data => { el.textContent = (data && data.label) ? data.label : fallback; }) - .catch(() => { el.textContent = fallback; }); + .catch(() => { clearTimeout(t); el.textContent = fallback; }); } function _movedEnough(lat, lon) {