5

How to Get user location latitude and longitude via telegram bot?

Module: Link

Code:

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);
});
Saeed Heidarizarei
  • 8,406
  • 21
  • 60
  • 103

2 Answers2

6

Solved ✔️

bot.on('location', (msg) => {
  console.log(msg.location.latitude);
  console.log(msg.location.longitude);
});
Saeed Heidarizarei
  • 8,406
  • 21
  • 60
  • 103
-1
bot.on('location', (msg) => {
  console.log(msg.message.location.latitude);
  console.log(msg.message.location.longitude);
});
    
Nick
  • 1
  • 1
  • 4