fix(geocode): replace AbortSignal.timeout with AbortController for compatibility
- AbortSignal.timeout not supported on all mobile browsers - Manual AbortController + setTimeout works everywhere - Fixes location not showing on dashboard and history first point Co-authored-by: Copilot <[email protected]>
This commit is contained in:
@@ -32,10 +32,12 @@
|
|||||||
if (key === _lastGeoKey) return;
|
if (key === _lastGeoKey) return;
|
||||||
_lastGeoKey = key;
|
_lastGeoKey = key;
|
||||||
const fallback = `${lat.toFixed(5)}, ${lon.toFixed(5)}`;
|
const fallback = `${lat.toFixed(5)}, ${lon.toFixed(5)}`;
|
||||||
fetch(`/api/geocode?lat=${lat}&lon=${lon}`, { signal: AbortSignal.timeout(4000) })
|
const ctrl = new AbortController();
|
||||||
.then(r => r.ok ? r.json() : null)
|
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; })
|
.then(data => { replayLocation.textContent = (data && data.label) ? data.label : fallback; })
|
||||||
.catch(() => { replayLocation.textContent = fallback; });
|
.catch(() => { clearTimeout(t); replayLocation.textContent = fallback; });
|
||||||
}
|
}
|
||||||
|
|
||||||
function scheduleGeocode(lat, lon) {
|
function scheduleGeocode(lat, lon) {
|
||||||
|
|||||||
+5
-3
@@ -199,10 +199,12 @@ _recenterBtn.addEventListener('click', function () {
|
|||||||
function reverseGeocode(lat, lon) {
|
function reverseGeocode(lat, lon) {
|
||||||
const el = document.getElementById('gps-location-name');
|
const el = document.getElementById('gps-location-name');
|
||||||
const fallback = `${lat.toFixed(5)}, ${lon.toFixed(5)}`;
|
const fallback = `${lat.toFixed(5)}, ${lon.toFixed(5)}`;
|
||||||
fetch(`/api/geocode?lat=${lat}&lon=${lon}`, { signal: AbortSignal.timeout(6000) })
|
const ctrl = new AbortController();
|
||||||
.then(r => r.ok ? r.json() : null)
|
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; })
|
.then(data => { el.textContent = (data && data.label) ? data.label : fallback; })
|
||||||
.catch(() => { el.textContent = fallback; });
|
.catch(() => { clearTimeout(t); el.textContent = fallback; });
|
||||||
}
|
}
|
||||||
|
|
||||||
function _movedEnough(lat, lon) {
|
function _movedEnough(lat, lon) {
|
||||||
|
|||||||
Reference in New Issue
Block a user