@bot.message_handler(content_types=['location'])
def location (message):
if message.location is not None:
coordinats = ("%s, %s" % (message.location.longitude, message.location.latitude))
def get_address_from_coords(coords):
PARAMS = {
"apikey":"KEY",
"format":"json",
"lang":"ru_RU",
"kind":"house",
"geocode": coords
}
try:
r = requests.get(url="https://geocode-maps.yandex.ru/1.x/", params=PARAMS)
json_data = r.json()
address_str = json_data["response"]["GeoObjectCollection"]["featureMember"][0]["GeoObject"]["metaDataProperty"]["GeocoderMetaData"]["AddressDetails"]["Country"]["AdministrativeArea"]["SubAdministrativeArea"]["Locality"]["LocalityName"]
return address_str
except Exception as e:
return "error"
if __name__ == '__main__':
address_str = get_address_from_coords("39.473602, 52.58381")
print(address_str)