Answer the question
In order to leave comments, you need to log in
Where to get location coordinates in telegram bot api?
Hello, you need to find a location by pressing a button, and then send it to the user
@bot.message_handler(content_types=['text'])
def send_location(message):
if message.text == "where I am?":
bot.send_chat_action(message.from_user.id, 'find_location')
bot.send_location(message.from_user.id, ) <- в этой строке загвоздка с координатами, откуда их брать?
Answer the question
In order to leave comments, you need to log in
First you need to request coordinates from the user, the button must have 'request_location' => true:
For more details, see: https://core.telegram.org/bots/api#replykeyboardmarkup and below about the location request button itself.
Then the answer will come (if the user shares), where the location will be indicated in the form:
By the way, if you want to show the location in numbers, then just send it via sendMessage. When sending sendLocation, telegram will send a mark on the map.
@bot.message_handler(content_types=['location'])
def handle_loc(message):
print(message.location)
Недавно столкнулся с такой же 'проблемой' (после решения не кажется сложной).
dispatcher.add_handler(MessageHandler(Filters.location, location))
def location(bot, update):
print(update.message.location)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question