【发布时间】:2018-06-23 02:59:53
【问题描述】:
我需要获取更新的用户位置。当我将我的实时位置发送给机器人时,我可以读取纬度和经度,但它们保持不变。我在地图上看到我的位置如何变化,但机器人无法更新坐标。
当我发送我的实时位置时,函数getLocation 保存我的消息并显示坐标。
def getLocation(bot, update, user_data):
msg = update.message
user_data['msg'] = msg
user_data['id'] = update.update_id
update.message.reply_text('lat: {}, lng: {}'.format(
msg.location.latitude, msg.location.longitude))
然后当我移动时,我想用/track 命令知道我的实际坐标,但它显示的是旧坐标。
def showCoordinates(bot, update, user_data):
# I need to update location here but I don't know
newLoc = user_data['msg']
update.message.reply_text('lat: {}, lng: {}'.format(
newLoc.location.latitude, newLoc.location.longitude))
这是我的调度员
dp = updater.dispatcher
dp.add_handler(MessageHandler(Filters.location,
getLocation,
pass_user_data=True))
dp.add_handler(CommandHandler('track',
showCoordinates,
pass_user_data=True))
我尝试在函数showCoordinates 中使用Update(user_data['id'], edit_message=user_data['loc']),但它对我不起作用。
【问题讨论】:
标签: python python-telegram-bot