-
-
Save Marak/fa5df9325b58cd27da2c 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
/** | |
* 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