Skip to content

Instantly share code, notes, and snippets.

@originalsouth
Created September 25, 2025 08:28
Show Gist options
  • Select an option

  • Save originalsouth/652e791b55db9bfd1ec86ddf8f53acbd to your computer and use it in GitHub Desktop.

Select an option

Save originalsouth/652e791b55db9bfd1ec86ddf8f53acbd to your computer and use it in GitHub Desktop.
Nominatim
import httpx
def retrieve_coordinates_from_address(
address: str, country_codes="NL"
) -> tuple[float, float]:
url = "https://nominatim.openstreetmap.org/search"
params = {
"q": address,
"format": "json",
"limit": 1,
"countrycodes": country_codes,
}
headers = {
"Accept": "application/json",
"User-Agent": "application/3.14159265358979 (contact: [email protected])",
}
with httpx.Client() as client:
response = client.get(url, headers=headers, params=params)
if response.status_code == 200:
data = response.json()
if data:
return float(data[0]["lat"]), float(data[0]["lon"])
else:
raise ValueError("No results found for the given address.")
else:
raise Exception(f"Error retrieving data: {response.status_code}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment