File size: 700 Bytes
c27b44a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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}')