Обратный геокодинг локации полученной ботом Telegram

Не могу разобраться с json ответом, как, куда и где его использовать, чтобы работал.

  • API ключ геокодинга есть, активен.
  • по HTTPS работает

Бот получает локацию от пользователя и в ответе должен прислать адрес из координат.

import telebot, cfg, kb, lg,

from telebot import types
from requests import get


bot = telebot.TeleBot(cfg.token)


@bot.message_handler(commands=['start'])
def start(message):
   bot.send_message(message.chat.id, lg.hello1e, reply_markup=kb.ikb1)


@bot.message_handler(content_types=["location"])
def location(message):
    if message.location is not None:
        bot.send_message == (message.location)
        bot.send_message(message.chat.id, "latitude: %s; longitude: %s" % (message.location.latitude, message.location.longitude))
        bot.send_message(message.chat.id, lg.hello5u, reply_markup=kb.kbsu1)

введите сюда описание изображения


Ответы (1 шт):

Автор решения: Violet

Получил я апи ключ.

@bot.message_handler(content_types=["location"])
def location(message):
    if message.location is not None:
        coord = str(message.location.longitude) + ',' + str(message.location.latitude)
        r = requests.get('https://geocode-maps.yandex.ru/1.x/?apikey=' + apikey + '&format=json&geocode=' + coord)
        
        if len(r.json()['response']['GeoObjectCollection']['featureMember']) > 0:
            address = r.json()['response']['GeoObjectCollection']['featureMember'][0]['GeoObject']['metaDataProperty'][
                'GeocoderMetaData']['text']
            bot.send_message(message.chat.id, 'Ваш адрес\n{}'.format(address))
        else:
            bot.send_message(message.chat.id, 'Не удалось получить Ваш адрес')

введите сюда описание изображения

→ Ссылка