'find nearest location using node js and mysql telegram bot

I was trying to do a telegram bot that finds a nearby location using node js and mysql. but after finding users coordinate(latitude,Longitude) in mycase (mylat,mylng). i cant take the values out of the parenthesis. here is the index.js N.B all the configurations are done.

bot.on('location', (msg) => {   
const mylat=msg.location.latitude;
const mylng=msg.location.longitude;

console.log(msg.location.latitude);
console.log(msg.location.longitude);
getNearestLocation(Latitude,longitude).then(res=>{
  bot.sendMessage(msg.chat.id,res)
  bot.sendLocation(msg.chat.id, Latitude,longitude)

})  
  }); 
console.log(mylat); // i can't print here

The variables doesn't work out of bot.on('location'.......... parenthesis



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source