【问题标题】:How can I interact with Telegram’s location?我如何与 Telegram 的位置进行交互?
【发布时间】:2020-05-21 19:58:28
【问题描述】:

下面我报告了一个简单的代码,通过单击“当前位置”按钮,我可以知道我的当前位置。 发送位置后,我希望能够发送一条消息,显示该位置的纬度和经度。 我不知道如何与 Telegram 发送的位置进行交互,您能帮帮我吗?

<?php

define ('url',"https://api.telegram.org/bot[botToken]/");

$update= file_get_contents('php://input');

$update= json_decode($update, TRUE);

$chatId= $update['message']['from']['id'];

$text= $update['message']['text'];

$button= '[{"text":"Current location", "request_location": true}]';

position($chatId, "Click the button to share your location", $button);



function position($IdChat, $text, $tastiera){

    $tastierino = '&reply_markup={"keyboard":['.$tastiera.'],"resize_keyboard": true,"one_time_keyboard": true}';
    $url=  url."sendMessage?chat_id=$IdChat&parse_mode=HTML&text=".urlencode($text).$tastierino;
    file_get_contents($url);
}

?>

【问题讨论】:

    标签: telegram telegram-bot php-telegram-bot


    【解决方案1】:

    当您向机器人发送位置时,它会收到带有 message 对象的更新,其中包含带有纬度和经度的 location 对象。

    您可以通过这样做获得纬度和经度:

    $latitude = $update['message']['location']['latitude'];
    $longitude = $update['message']['location']['longitude'];
    

    【讨论】:

    • 非常感谢。
    • 嗨@Lorenzo,如果这个或任何答案解决了您的问题,请点击复选标记考虑accepting it。这向更广泛的社区表明您已经找到了解决方案,并为回答者和您自己提供了一些声誉。没有义务这样做。
    猜你喜欢
    • 2015-09-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-11-19
    相关资源
    最近更新 更多