Telegram 如何与电报互动’;什么地方?
下面我报告了一个简单的代码,通过单击“current location”(当前位置)按钮可以知道我的当前位置。 一旦我发送了位置,我希望能够发送一条消息,显示位置的纬度和经度。 我不知道如何与通过电报发送的位置进行交互,你能帮我吗Telegram 如何与电报互动’;什么地方?,telegram,telegram-bot,php-telegram-bot,Telegram,Telegram Bot,Php Telegram Bot,下面我报告了一个简单的代码,通过单击“current location”(当前位置)按钮可以知道我的当前位置。 一旦我发送了位置,我希望能够发送一条消息,显示位置的纬度和经度。 我不知道如何与通过电报发送的位置进行交互,你能帮我吗 <?php define ('url',"https://api.telegram.org/bot[botToken]/"); $update= file_get_contents('php://input'); $update= json_decode(
<?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);
}
?>
当您向bot发送位置时,它会收到一个对象的更新,该对象包含具有纬度和经度的对象
通过执行以下操作,可以获得纬度和经度:
$latitude = $update['message']['location']['latitude'];
$longitude = $update['message']['location']['longitude'];
非常感谢。嗨,洛伦佐,如果这个或任何答案都解决了你的问题,请点击检查标记来考虑。这向更广泛的社区表明,你已经找到了一个解决方案,并给回答者和你自己带来了一些声誉。没有义务这样做。