Last active
August 29, 2015 13:55
-
-
Save rla/8689077 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var geocoder = require('geocoder'); | |
var Promise = require('bluebird'); | |
function query(location) { | |
console.log("Geocoding: %s", location); | |
var locator = Promise.defer(); | |
geocoder.geocode(location, function(err, data) { | |
if (err !== null || data.results === undefined || data.results.length < 1) { | |
console.log("%s results: false", location); | |
console.log("-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- --"); | |
return; | |
} | |
var rsp = data.results[0]; | |
locator.resolve(rsp); | |
// console.log("formatted address: %s", rsp.formatted_address); | |
// console.log("-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- --"); | |
}); | |
return locator.promise; | |
}; | |
function pr(rsp) { | |
console.log('Geocode response:', rsp); | |
}; | |
/* | |
query('New York, NY').then(pr); | |
query('11217').then(pr); | |
query('66666').then(pr); | |
query('6666').then(pr); | |
query('London, UK').then(pr); | |
*/ | |
['New York', '11217', '66666', '6666', 'London'].reduce(function(seq, loc) { | |
return seq.then(function() { | |
return query(loc).then(pr); | |
}); | |
}, new Promise()).then(function() { console.log('done') }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment