S
S
stamdyscias2016-06-26 12:22:12
Python
stamdyscias, 2016-06-26 12:22:12

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

3 answer(s)
E
Eugene, 2016-06-26
@xmax

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.

T
tyurikov, 2019-09-03
@tyurikov

@bot.message_handler(content_types=['location'])
def handle_loc(message):
    print(message.location)

прилетело то что надо:
{'longitude': xx.xxxxxx, 'latitude': yy.yyyyyy}

M
Mr_Pod, 2018-06-20
@Mr_Pod

Недавно столкнулся с такой же 'проблемой' (после решения не кажется сложной).

Кратко:
Настроить mesage handler ловить update с непустым location после нажатия кнопки
Длинно:
  1. Для юзеров pyTelegramBotAPI
  2. Для ребяток, которые используют python-telegram-bot:
    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 question

Ask a Question

731 491 924 answers to any question