实时地理位置
Telegram 允许在聊天中发送用户的实时地理位置,还可以选择设置接近提醒。
发送实时位置
inputGeoPointEmpty#e4c123d6 = InputGeoPoint;inputGeoPoint#48222faf flags:# lat:double long:double accuracy_radius:flags.0?int = InputGeoPoint;inputMediaGeoLive#971fa843 flags:# stopped:flags.0?true geo_point:InputGeoPoint heading:flags.2?int period:flags.1?int proximity_notification_radius:flags.3?int = InputMedia;---functions---messages.sendMedia#ac55d9c1 flags:# silent:flags.5?true background:flags.6?true clear_draft:flags.7?true noforwards:flags.14?true update_stickersets_order:flags.15?true invert_media:flags.16?true allow_paid_floodskip:flags.19?true peer:InputPeer reply_to:flags.0?InputReplyTo media:InputMedia message:string random_id:long reply_markup:flags.2?ReplyMarkup entities:flags.3?Vector<MessageEntity> schedule_date:flags.10?int send_as:flags.13?InputPeer quick_reply_shortcut:flags.17?InputQuickReplyShortcut effect:flags.18?long allow_paid_stars:flags.21?long suggested_post:flags.22?SuggestedPost = Updates;messages.editMessage#dfd14005 flags:# no_webpage:flags.1?true invert_media:flags.16?true peer:InputPeer id:int message:flags.11?string media:flags.14?InputMedia reply_markup:flags.2?ReplyMarkup entities:flags.3?Vector<MessageEntity> schedule_date:flags.15?int quick_reply_shortcut_id:flags.17?int = Updates;
要发送实时地理位置,请使用messages.sendMedia和inputMediaGeoLive media。
inputMediaGeoLive允许将地理位置作为inputGeoPoint发送,其中包含浮点数形式的纬度和经度,以及可选的以米为单位的距离。客户端还可以提供方向(以度为单位,1-360 度),用于指示用户的方向,以及当前位置的有效期。accuracy_radius
headingperiodproximity_notification_radius
为了实现实时地理位置的“实时”功能, 应该使用messages.editMessage 定期更新发送的地理位置信息,最多每秒更新一次。period
要停止共享位置,请将inputGeoPointEmpty作为位置传递,并stopped在最后一次messages.editMessage调用中将该标志设置为 true。
接收实时位置信息
geoPoint#b2a2f663 flags:# long:double lat:double access_hash:long accuracy_radius:flags.0?int = GeoPoint; messageMediaGeoLive#b940c666 flags:# geo:GeoPoint heading:flags.0?int period:int proximity_notification_radius:flags.1?int = MessageMedia;updateGeoLiveViewed#871fb939 peer:Peer msg_id:int = Update;
客户端将收到一条消息,其中包含消息媒体 GeoLive,以及发送者传递的信息;当地理位置消息被标记为已读时,将生成 一条更新 GeoLiveViewed 消息。
地理位置会定期通过updateEditMessage/updateEditChannelMessage更新进行更新。
实时位置预览
inputWebFileGeoPointLocation#9f2221c9 geo_point:InputGeoPoint access_hash:long w:int h:int zoom:int scale:int = InputWebFileLocation;inputGeoPoint#48222faf flags:# lat:double long:double accuracy_radius:flags.0?int = InputGeoPoint;---functions---upload.getWebFile#24e6818d location:InputWebFileLocation offset:int limit:int = upload.WebFile;
可以通过将接收到的geoPoint传递给upload.getWebFile来生成地图预览,从而下载地图的图像预览。
- geo_pointlat由geoPointlongaccuracy_radius的参数生成
- access_hash是geoPoint的访问哈希值
- w- 应用缩放前的地图宽度(像素);16-1024
- h- 应用缩放前的地图高度(像素);16-1024
- zoom地图缩放级别:13-20
- scale地图比例尺:1-3
然后按照此处的说明下载图像»
近距离警报
messageActionGeoProximityReached#98e0d697 from_id:Peer to_id:Peer distance:int = MessageAction;messageService#7a800e0a flags:# out:flags.1?true mentioned:flags.4?true media_unread:flags.5?true reactions_are_possible:flags.9?true silent:flags.13?true post:flags.14?true legacy:flags.19?true id:int from_id:flags.8?Peer peer_id:Peer saved_peer_id:flags.28?Peer reply_to:flags.3?MessageReplyHeader date:int action:MessageAction reactions:flags.20?MessageReactions ttl_period:flags.25?int = Message;
如果:
- 用户proximity_notification_radius在发送位置信息时设置了位置信息。
- 多个用户在同一聊天窗口中共享位置信息
- 另一位用户靠近到距离proximity_notification_radius第一位用户几米以内,并相应地更新了自己的位置。
为所有聊天成员生成updateNewMessage/updateNewChannelMessage,其中包含一个带有操作messageActionGeoProximityReached的消息服务:
- messageActionGeoProximityReached.to_id是启用近距离警报的对等节点
- messageActionGeoProximityReached.from_id是现在靠近的同伴messageActionGeoProximityReached.to_id
- messageActionGeoProximityReached.distance是它们之间的距离,单位为米