J
J
Junior_0072020-09-29 23:50:22
Python
Junior_007, 2020-09-29 23:50:22

How to get location in Telegram bot from ReplyKeyboardMarkup?

I am writing a cart bot that would return the user's location when clicking ReplyKeyboardMarkup.
The code:

import telebot
from telebot import types
bot = telebot.TeleBot(API Token)

@bot.message_handler(commands=["start"])
def start (message):
    #Клавиатура с кнопкой запроса локации
    keyboard = types.ReplyKeyboardMarkup(row_width=1, resize_keyboard=True)
    button_geo = types.KeyboardButton(text="Отправить местоположение", request_location=True)
    keyboard.add(button_geo)
    bot.send_message(message.chat.id, "Поделись местоположением", reply_markup=keyboard)

 #Получаю локацию
@bot.message_handler(content_types=['location'])
def location (message):
    if message.location is not None:
        print(message.location)
        print(message)

bot.polling(none_stop = True)
input()


As a result, a button is displayed in the messenger, when it is pressed, Telegram asks whether to send geodata exactly, when confirmation is received, geodata does not come. I checked the receipt of data by the MethodGetUpdates request, there is no data, the answer. {'ok': True, 'result': []}
If you send geodata not through the ReplyKeyboardMarkup button, but through the interface of the "geoposition" telegram itself, the data comes.
I can not figure out what is wrong, why the button does not work.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
soremix, 2020-09-30
@SoreMix

Everything is working. Where are you trying to send geolocation from? Is geolocation access for Telegram enabled on your phone?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question