fix: use Ola Maps autocomplete endpoint
Browse files- backend/api/server.py +15 -4
backend/api/server.py
CHANGED
|
@@ -76,23 +76,34 @@ async def _ola_geocode(q: str) -> list | None:
|
|
| 76 |
try:
|
| 77 |
async with httpx.AsyncClient(timeout=6.0) as client:
|
| 78 |
res = await client.get(
|
| 79 |
-
"https://api.olamaps.io/places/v1/
|
| 80 |
-
params={
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 81 |
headers={"X-Request-Id": "eudora-geocode"},
|
| 82 |
)
|
| 83 |
if res.status_code != 200:
|
| 84 |
return None
|
| 85 |
data = res.json()
|
| 86 |
-
results = data.get("
|
| 87 |
normalized = []
|
| 88 |
for r in results[:6]:
|
|
|
|
| 89 |
loc = r.get("geometry", {}).get("location", {})
|
| 90 |
lat = loc.get("lat") or loc.get("latitude")
|
| 91 |
lon = loc.get("lng") or loc.get("longitude")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 92 |
if not lat or not lon:
|
| 93 |
continue
|
| 94 |
normalized.append({
|
| 95 |
-
"display_name": r.get("
|
| 96 |
"lat": str(lat),
|
| 97 |
"lon": str(lon),
|
| 98 |
"place_id": r.get("place_id", ""),
|
|
|
|
| 76 |
try:
|
| 77 |
async with httpx.AsyncClient(timeout=6.0) as client:
|
| 78 |
res = await client.get(
|
| 79 |
+
"https://api.olamaps.io/places/v1/autocomplete",
|
| 80 |
+
params={
|
| 81 |
+
"input": q,
|
| 82 |
+
"api_key": key,
|
| 83 |
+
"location": "22.7196,75.8577",
|
| 84 |
+
"radius": 50000,
|
| 85 |
+
},
|
| 86 |
headers={"X-Request-Id": "eudora-geocode"},
|
| 87 |
)
|
| 88 |
if res.status_code != 200:
|
| 89 |
return None
|
| 90 |
data = res.json()
|
| 91 |
+
results = data.get("predictions") or []
|
| 92 |
normalized = []
|
| 93 |
for r in results[:6]:
|
| 94 |
+
# Ola autocomplete: geometry.location has lat/lng
|
| 95 |
loc = r.get("geometry", {}).get("location", {})
|
| 96 |
lat = loc.get("lat") or loc.get("latitude")
|
| 97 |
lon = loc.get("lng") or loc.get("longitude")
|
| 98 |
+
# Some responses nest under place_details
|
| 99 |
+
if not lat:
|
| 100 |
+
loc2 = r.get("place_details", {}).get("geometry", {}).get("location", {})
|
| 101 |
+
lat = loc2.get("lat")
|
| 102 |
+
lon = loc2.get("lng")
|
| 103 |
if not lat or not lon:
|
| 104 |
continue
|
| 105 |
normalized.append({
|
| 106 |
+
"display_name": r.get("description") or r.get("formatted_address") or r.get("name", ""),
|
| 107 |
"lat": str(lat),
|
| 108 |
"lon": str(lon),
|
| 109 |
"place_id": r.get("place_id", ""),
|