Spaces:
Running
Running
import requests | |
import json | |
from urllib.parse import quote | |
def get_geo_coords(address, access_token): | |
base_url = "https://us1.locationiq.com/v1/search" | |
headers= {"key: " + f"{access_token}", "Content-Type: application/json",} | |
url = f"{base_url}?key={access_token}&q={quote(address)}&format=json" | |
response = requests.get(url) | |
rjson = json.loads(response.content) | |
return (float(rjson[0]['lat']), float(rjson[0]['lon'])) | |
if __name__ == "__main__": | |
address = 'Grytviken, South Georgia' #'Rio de Janerio, Argentina' | |
(lat, lon) = get_geo_coords(address) #'307 Pauly Drive, Englewood, Ohio, USA') | |
print(f'{address}: Lat = {float(lat):.2f}, Lon = {float(lon):.2f}') | |