通过电报机器人获取用户位置纬度和经度

时间:2018-02-06 20:37:41

标签: javascript node.js telegram-bot node-telegram-bot-api

如何通过电报机器人获取用户位置纬度和经度?

模块:Link

代码:

bot.onText(/getLocation/, (msg) => {
  const opts = {
    reply_markup: JSON.stringify({
      keyboard: [
        [{text: 'Location', request_location: true}],
        [{text: 'Contact', request_contact: true}],
      ],
      resize_keyboard: true,
      one_time_keyboard: true,
    }),
  };
  bot.sendMessage(msg.chat.id, 'Contact and Location request', opts);
});

1 个答案:

答案 0 :(得分:1)

解决了✔️

bot.on('location', (msg) => {
  console.log(msg.location.latitude);
  console.log(msg.location.longitude);
});