fix(geocode): accurate street name + always shows on dashboard

- Cache key uses 4 decimal places (~11m) instead of 3 (~111m) for correct street
- Dashboard geocodes on first GPS fix, then again every >50m moved (throttled 15s)
- Removed stale console.log

Co-authored-by: Copilot <[email protected]>
This commit is contained in:
Mathieu Moran
2026-08-10 03:21:37 -04:00
co-authored by Copilot
parent c188fb9d14
commit 11f07dec38
2 changed files with 17 additions and 9 deletions
+4 -4
View File
@@ -93,10 +93,10 @@ import functools
import urllib.request
@functools.lru_cache(maxsize=512)
def _geocode_cached(lat3, lon3):
def _geocode_cached(lat4, lon4):
"""Try Nominatim first (street-level), fall back to reverse_geocoder (city)."""
lat = lat3 / 1000.0
lon = lon3 / 1000.0
lat = lat4 / 10000.0
lon = lon4 / 10000.0
try:
url = f"https://nominatim.openstreetmap.org/reverse?format=jsonv2&lat={lat}&lon={lon}&accept-language=en"
req = urllib.request.Request(url, headers={"User-Agent": "yaris-obd/1.0"})
@@ -126,7 +126,7 @@ def geocode_route():
except (KeyError, ValueError):
return jsonify(error="lat and lon required"), 400
# Round to 3 decimals (~111m precision) for cache key
label = _geocode_cached(round(lat, 3) * 1000 // 1, round(lon, 3) * 1000 // 1)
label = _geocode_cached(int(round(lat, 4) * 10000), int(round(lon, 4) * 10000))
return jsonify(label=label)
@app.route('/api/dash/devices')