So, i was working in on multi API project where ,there's one part where one had to enter the address , for where you want to get the weather outputs, and i am stuck in a part where i can take the API values of long. and lat. converted out of a address string and pass it to a API for weather outputs.as i can't access the API output of one to another. The request url is like this:
request({url:url,json:true}, (error,response) => {
console.log(response.body.current.weather_descriptions[0] +' The temperature is '+chalk.inverse(response.body.current.temperature)+' but it feels like '+ chalk.inverse(response.body.current.feelslike))
})
ok, i found an answer using call back function, i have answered below the code.
const geoCode = (geoUrl, callback) => {
request({url:geoUrl,json:true}, (error,response) => {
if(error)
{
console.log('Unable to connect to the server.....')
}
else{
callback(undefined,{
latitude:response.body.data[0].latitude,
longitude:response.body.data[0].longitude
})
}
})
}
geoCode(geoUrl,(error,data) =>
{
var url = 'youur api'
url = url+data.latitude+","+data.longitude
// console.log(url)
request({url:url,json:true}, (error,response) => {
if(error)
{
console.log('Unable to connect to the server.....')
}
else{
console.log(response.body.current.weather_descriptions[0] +' The temperature is '+chalk.inverse(response.body.current.temperature)+' but it feels like '+ chalk.inverse(response.body.current.feelslike))
}
})
})