14 lines
584 B
Python
14 lines
584 B
Python
import httpx
|
|
|
|
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", {})
|
|
return address.get("city") or address.get("town") or address.get("village") or address.get("county") or f"{lat:.2f},{lon:.2f}"
|