node.js - javascript use response from function in calling function -
i've got basic example of of node-geocoder, can't response bubble calling function
var address = userupdates.address + " " + userupdates.city + ", " + userupdates.state + " " + userupdates.zip; geocoder.geocode(address) .then(function(res) { console.log(res); }) .catch(function(err) { console.log(err); });
the console.log produces correct json
[ { latitude: 35, longitude: -78.5, country: 'united states', city: 'clayton', state: 'north carolina', statecode: 'nc', zipcode: '27520', streetname: 'main st', streetnumber: '100', countrycode: 'us' } ]
but can't assign res persist outside geocoder.geocode function
have tried creating global variable outside of geocoder.geocode function hold value?
var globalres = null; geocoder.geocode(address) .then(function(res) { globalres = res; console.log(res); }) .catch(function(err) { console.log(err); });
Comments
Post a Comment