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

Get user location latitude and longitude via telegram bot

如何通过telegram bot获取用户所在位置的经纬度?

模块: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);
});

已解决✔️

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