Created
November 16, 2022 21:26
-
-
Save xsa-dev/ac15cc52210a5ee843f0593bd889bfe0 to your computer and use it in GitHub Desktop.
nu get_lat_lon
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 get_lat_lon(street=None, city='Москва') -> tuple[float, float]: | |
if street is None: | |
raise Exception('error! street is None') | |
p = { | |
'street': street, | |
'city': city, | |
'format': 'json', | |
'zoom': 10 | |
} | |
r = requests.get('https://nominatim.openstreetmap.org/search', params=p) | |
r.raise_for_status() | |
o = r.json() | |
x, y = r.json()[0]['lat'], r.json()[0]['lon'] | |
return x, y | |
# test | |
print(get_lat_lon('Красносельский 1-й пер.,|13', 'Москва')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment