如果发送的消息是带有TELETHON的电报中的位置共享消息,我可以获取该位置的经度和纬度吗

问题描述 投票:0回答:1

我正在抓取电报,我可以在聊天中使用 client.iter_messages 获取每个消息实例,但如果消息实例是位置共享消息,我想获取位置的纬度和经度。

for message in client.iter_messages('John'):
     print(message.text)   #prints message
     ------------------    #I want the latitude and longitude of the location if the message is a location share message and not a text message

如果有一点帮助,我们将不胜感激, 谢谢你。

python-3.x telegram telethon telegram-api
1个回答
3
投票

仅当消息是位置共享消息时才采取行动(

message.geo
),否则不需要

location = message.geo   #returns a GeoPoint object if the message is a location share message else returns None
if location is not None:
     longitude = location.long
     latitude = location.lat
     print(longitude, latitude)
© www.soinside.com 2019 - 2024. All rights reserved.