feat(geocode): fully offline reverse geocode via local Pi API
- Remove all Nominatim/external calls from frontend - Add /api/geocode?lat=&lon= route using reverse_geocoder (20MB offline KD-tree) - JS hits /api/geocode only — works with no internet at all - Falls back to raw coords if Pi route fails - Add reverse_geocoder to requirements.txt Co-authored-by: Copilot <[email protected]>
This commit is contained in:
+4
-14
@@ -32,20 +32,10 @@
|
||||
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' },
|
||||
signal: AbortSignal.timeout(5000),
|
||||
})
|
||||
.then(r => r.ok ? r.json() : null)
|
||||
.then(data => {
|
||||
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(',') || fallback;
|
||||
})
|
||||
.catch(() => { replayLocation.textContent = fallback; });
|
||||
fetch(`/api/geocode?lat=${lat}&lon=${lon}`, { signal: AbortSignal.timeout(4000) })
|
||||
.then(r => r.ok ? r.json() : null)
|
||||
.then(data => { replayLocation.textContent = (data && data.label) ? data.label : fallback; })
|
||||
.catch(() => { replayLocation.textContent = fallback; });
|
||||
}
|
||||
|
||||
function scheduleGeocode(lat, lon) {
|
||||
|
||||
Reference in New Issue
Block a user