【问题标题】:Get the current location from telegram using API使用 API 从电报中获取当前位置
【发布时间】:2019-01-09 02:44:08
【问题描述】:

我有一个电报机器人,我使用自定义按钮与用户交互。我现在需要使用 GPS 信息获取当前位置。是否可以使用电报 API 从设备获取纬度和经度?

这是我的 PHP 代码:

  if($text == '/start')
  {
    $botid = $xtokenid;
    $chatid = $chat_id;
    $reply = "Bem vindo ao EYB18, canal de informações online!";
    $url = "https://api.telegram.org/bot$botid/sendMessage";

    $keyboard = array('keyboard' => array(array("Localização")),'resize_keyboard' => true,'one_time_keyboard' => false,'request_location' => true);

    $postfields = array('chat_id' => "$chatid",'text' => "$reply",'reply_markup' => json_encode($keyboard));

    $str = str_replace('\\\\', '\\', $postfields);

    print_r($str);
    if (!$curld = curl_init()) {
    exit;
    }

    curl_setopt($curld, CURLOPT_POST, true);
    curl_setopt($curld, CURLOPT_POSTFIELDS, $str);
    curl_setopt($curld, CURLOPT_URL,$url);
    curl_setopt($curld, CURLOPT_RETURNTRANSFER, true);

    $output = curl_exec($curld);

    curl_close ($curld);
  }

Tks.

【问题讨论】:

    标签: api gps telegram


    【解决方案1】:

    您正在发送一个键盘,它将要求用户发送他们的位置。如果他们按下此按钮,或者即使他们从地图发送任何位置,您的机器人也会获得包含位置对象的消息对象。位置对象包含经度和纬度。

    这里是消息对象属性的完整列表:https://core.telegram.org/bots/api#message

    这里是位置对象:https://core.telegram.org/bots/api#location

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-06-30
      • 2016-12-05
      • 1970-01-01
      • 2012-06-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-12-01
      相关资源
      最近更新 更多