Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
/**
* Geocoder
*
* You pass it an address and it returns a geocoded response. You will need
* a Geocodio API Key.
*
* @param {string} api_key Your geocodio API Key
* @param {string} address An address.
*
* curl--data 'api_key=XXXXX&address=123 Maple Lane, Everywhere USA' http://hook.io/desmondmorris/geocoder
*
**/
var Geocodio = require('geocodio');
module.exports = function geocode (hook) {
var Geocodio = require('geocodio');
var geocodio = new Geocodio({
api_key: hook.env.GEOCODIO_API_KEY || hook.params.api_key || null
});
geocodio.get('geocode', {q: hook.params.address}, function(err, response){
if (err) {
hook.debug(err.message);
hook.res.end(JSON.stringify(err, true, 2));
}
else {
hook.res.end(JSON.stringify(response, true, 2));
}
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment