Last active
April 29, 2024 22:35
-
-
Save rodrigobertin/0b256f2a651ee141187c406d71adac5f to your computer and use it in GitHub Desktop.
This file contains 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 requests | |
def obtener_latitud_longitud(address): | |
# Construir la URL de la API de OpenStreetMap | |
url = f"https://nominatim.openstreetmap.org/search.php?q={address}&format=jsonv2" | |
# Realizar la solicitud GET a la API de OpenStreetMap | |
response = requests.get(url) | |
# Verificar si la solicitud fue exitosa | |
if response.status_code == 200: | |
# Analizar la respuesta JSON | |
data = response.json() | |
if data: | |
# Extraer la latitud y longitud de los resultados | |
latitud = data[0]['lat'] | |
longitud = data[0]['lon'] | |
return latitud, longitud | |
# En caso de error o si no se encontraron resultados, retornar None | |
return None, None |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment