Created
September 25, 2025 08:28
-
-
Save originalsouth/652e791b55db9bfd1ec86ddf8f53acbd to your computer and use it in GitHub Desktop.
Nominatim
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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