I need to retrieve the coordinate that the request sends me back.
The request is correct, on body
body I can access lat and lon. The thing is, the request is inside another function called latlongfunc
. How can I get access to the body outside the request call?
What I've already tried:
create a variable
before the call, then, modify it inside the call, and finally return it on the end of the function latlongfunc.
It doesn't work...
IMPORTANT: The request IS working, the problem is on how to access the body outside the request.
const request = require('request')
console.log("Here.")
var latlongfunc = async (fullAddress) => {
var options = {
url: `https://nominatim.openstreetmap.org/search/${fullAddress}`,
json: true, // JSON strigifies the body automatically
headers: {
'User-Agent': 'request'
}
};
request(options, (err, res, body) => {
if(body.length > 0){
// A body was received
var coordinate = {
lat: body[0].lat,
lon: body[0].lon
}
return coordinate
}else{
console.log("Something wrong happened")
}
})
}
module.exports = {
latlongfunc
};