Skip to content

Instantly share code, notes, and snippets.

@dca
Last active March 4, 2016 13:24
Show Gist options
  • Save dca/9ba39cacc5c14c22baf5 to your computer and use it in GitHub Desktop.
Save dca/9ba39cacc5c14c22baf5 to your computer and use it in GitHub Desktop.
module.exports = {
dashboarddistance: function(a, b, c, d, callback) {
var ds = 0;
var distance = require('google-distance');
distance.get({
index: 1,
origin: a + ',' + b,
destination: c + ',' + d
}, function(err, data) {
if (err) {
console.log("a");
ds = 0;
return callback(err, ds);
} else {
console.log("b");
ds = data.distance;
return callback(null, ds);
}
});
},
};
var example = require('./example.js');
example.dashboarddistance(a, b, c, d, function(err, distance) {
if (err) {
// dosomething and return
return ;
}
console.log(distance);
});
@rahul201992
Copy link

As You will see in the above code by @dca Hsu it returns distance in variable in distance.
When I use console.log(distance); inside function it gives an output.

But if I want to store this distance in a variable 'finaldistance' and add it to a response what should i do.

I think the scope of distance is only inside callback function that i have passed inside function dashboarddistance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment