D
D
dmitrijsomov4832018-09-17 21:55:50
Python
dmitrijsomov483, 2018-09-17 21:55:50

[Python Telegram Bot] How to handle location(latitude,longitude) values?

@bot.message_handler(commands=["geo"])
def geo(message):
    keyboard = types.ReplyKeyboardMarkup(row_width=1, resize_keyboard=True)
    button_geo = types.KeyboardButton(text="Отправить местоположение", 
    request_location=True)
    keyboard.add(button_geo)

I send my geolocation to the bot, in json format there is latitude and longitude (latitude, longitude), and if I try to get this data, it gives an error.
print(message.location.latitude)
 >> AttributeError: 'NoneType' object has no attribute 'latitude'

If you try to display it like this, it gives an empty value, although there is a value when viewing json through / getUpdates.
print(message.location)
>>None

How to get location values?
"location":{"latitude":xx.xxxxxx,"longitude":yy.yyyyyy}}}]}

Answer the question

In order to leave comments, you need to log in

2 answer(s)
N
Nastya Sukharik, 2018-09-18
@nastya_cyxarik

Isn't message equal to location ?
then message.latitude will return a value? Or did I misunderstand?

A
apiwi, 2021-06-06
@apiwi

message.location.latitude

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question