Skip to content

Instantly share code, notes, and snippets.

@xsa-dev
Created November 16, 2022 21:26
Show Gist options
  • Save xsa-dev/ac15cc52210a5ee843f0593bd889bfe0 to your computer and use it in GitHub Desktop.
Save xsa-dev/ac15cc52210a5ee843f0593bd889bfe0 to your computer and use it in GitHub Desktop.
nu get_lat_lon
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