I am using a library called node-geocoder in express js which has the following code:
var NodeGeocoder = require('node-geocoder');
var options = {
provider: 'google',
// Optional depending on the providers
httpAdapter: 'https', // Default
apiKey: 'YOUR_API_KEY', // for Mapquest, OpenCage, Google Premier
formatter: null // 'gpx', 'string', ...
};
var geocoder = NodeGeocoder(options);
// Using callback
geocoder.geocode('29 champs elysée paris', function(err, res) {
console.log(res);
});
The response variable(res) in the geocode method's callback function holds an object with location properties such as latitutde and longitude. The link for this package is here
I was wondering if there was a way to use that response variable outside of the callback function in the geocode method. I need to pull the latitude and longitude properties and I don't want to keep the rest of the code within that callback function.
As a noob I tried just returning the object and storing it in a variable like so:
var object = geocoder.geocode('29 champs elysée paris', function(err, res) {
return res;
});
This doesn't work since it's in the callback and not returned in the actual geocode method.