This commit is contained in:
2026-01-24 19:09:37 -05:00
parent 97ca92b945
commit 52400f888e
3 changed files with 36 additions and 46 deletions

View File

@@ -1,17 +1,13 @@
import requests
import httpx
def get_city_name(lat, lon):
try:
r = requests.get(
async def get_city_name_async(lat, lon):
async with httpx.AsyncClient(timeout=5) as client:
r = await client.get(
"https://nominatim.openstreetmap.org/reverse",
params={"lat": lat, "lon": lon, "format": "json", "zoom": 10, "addressdetails": 1},
headers={"User-Agent": "AreWeBuriedApp/1.0"}
)
r.raise_for_status()
data = r.json()
address = data.get("address", {})
city = address.get("city") or address.get("town") or address.get("village") or address.get("county") or f"{lat:.2f},{lon:.2f}"
return city
except Exception as e:
print("Reverse geocoding error:", e)
return f"{lat:.2f},{lon:.2f}"
address = data.get("address", {})
return address.get("city") or address.get("town") or address.get("village") or address.get("county") or f"{lat:.2f},{lon:.2f}"