fix: BUG-13 — server geocode returns raw coords instead of location names
Root cause: server _geocode_cached() returned None → /api/geocode
returned HTTP 204 with no body. JS frontend treated 204 as success,
r.json() on empty body threw → showed raw-coordinate fallback.
Server fixes:
- _geocode_cached() now always returns a non-empty string (coordinate
fallback when both Nominatim and reverse_geocoder fail)
- /api/geocode always returns HTTP 200 with {label: '...'} (never 204)
- /api/geocode/batch always includes every coord key in result dict
- Nominatim call: jsonv2 + accept-language=en (aligned with Pi)
- reverse_geocoder: mode=1 (aligned with Pi)
Pi alignment:
- _geocode_cached() now checks for empty reverse_geocoder label before
returning, falling through to coordinate string (same guard as server)
This commit is contained in:
@@ -167,7 +167,8 @@ import urllib.request
|
||||
|
||||
@functools.lru_cache(maxsize=512)
|
||||
def _geocode_cached(lat4, lon4):
|
||||
"""Try Nominatim first (street-level), fall back to reverse_geocoder (city)."""
|
||||
"""Try Nominatim first (street-level), fall back to reverse_geocoder (city),
|
||||
then raw coordinates. Always returns a non-empty label string."""
|
||||
lat = lat4 / 10000.0
|
||||
lon = lon4 / 10000.0
|
||||
try:
|
||||
@@ -188,7 +189,10 @@ def _geocode_cached(lat4, lon4):
|
||||
results = rg.search([(lat, lon)], mode=1, verbose=False)
|
||||
if results:
|
||||
r = results[0]
|
||||
return ", ".join(p for p in [r.get("name", ""), r.get("admin1", "")] if p)
|
||||
label = ", ".join(p for p in [r.get("name", ""), r.get("admin1", "")] if p)
|
||||
if label:
|
||||
return label
|
||||
# Last resort — raw coordinates so the frontend never gets an empty label
|
||||
return f"{lat:.5f}, {lon:.5f}"
|
||||
|
||||
@app.route('/api/geocode')
|
||||
|
||||
Reference in New Issue
Block a user