Skip to content

Instantly share code, notes, and snippets.

@Marak
Forked from desmondmorris/hookio-geocoder.js
Last active August 29, 2015 14:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Marak/fa5df9325b58cd27da2c to your computer and use it in GitHub Desktop.
Save Marak/fa5df9325b58cd27da2c to your computer and use it in GitHub Desktop.
/**
* 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) {
// Environment variables not supported (yet?)
var geocodio = new Geocodio({
api_key: hook.env.GEOCODIO_API_KEY || hook.params.api_key || null
});
geocodio.geocode(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