Node library for geocoding and reverse geocoding. Can be use as a nodejs library or as a command line
npm install -g node-geocoder
geocoder --provider google 'Fornino, 187 Bedford Ave, Brooklyn, NY 11211'npm install node-geocoder
var geocoderProvider = 'google';
var httpAdapter = 'http';
// optionnal
var extra = {
apiKey: 'YOUR_API_KEY', // for mapquest, opencagedata, Google premier
formatter: null // 'gpx', 'string', ...
};
var geocoder = require('node-geocoder').getGeocoder(geocoderProvider, httpAdapter, extra);
// Using callback
geocoder.geocode('29 champs elysée paris', function(err, res) {
console.log(res);
});
// Or using Promise
geocoder.geocode('29 champs elysée paris')
.then(function(res) {
console.log(res);
})
.catch(function(err) {
console.log(err);
});
// output :
[{
latitude: 48.8698679,
longitude: 2.3072976,
country: 'France',
countryCode: 'FR',
city: 'Paris',
zipcode: '75008',
streetName: 'Champs-Élysées',
streetNumber: '29',
state: 'Île de France',
stateCode: 'IDF'
}]
## Advenced usage (only google provider)
geocoder.geocode({address: '29 champs elysée', country: 'France', zipcode: '75008'}, function(err, res) {
console.log(res);
});
// Reverse example
// Using callback
geocoder.reverse(45.767, 4.833, function(err, res) {
console.log(res);
});
// Or using Promise
geocoder.reverse(45.767, 4.833)
.then(function(res) {
console.log(res);
})
.catch(function(err) {
console.log(err);
});google: GoogleGeocoder support address geocoding and reverse geocoding, useextra.clientIdandextra.apiKey(privateKey) for business licence, you can also useextra.languagefor specify language. Note that 'https' is required when using an apiKeyfreegeoip: FreegeoipGeocoder support ip geocodingdatasciencetoolkit: DataScienceToolkitGeocoder supports ip v4 geocoding and address geocoding, useextra.hostfor specify a local instanceopenstreetmap: OpenStreetMapGeocoder support address geocoding and reverse geocodingmapquest: MapQuestGeocoder support address geocoding and reverse geocoding need an apiKeyopenmapquest: Open MapQuestGeocoder (based on OpenStreetMapGeocoder) support address geocoding and reverse geocoding need an apiKeyagol: ArcGis Online Geocoding service, supports geocoding and reverse. Requires a client_id & client_secrettomtom: TomTomGeocoder support address geocoding , you need to specifyextra.apiKeynominatimmapquest: OpenStreetMap nominatim geocoder, support address, and reverse geocodingopencage: uses multiple open sources, support address, reverse geocoding, you need to specifyextra.apiKey
http: This adapter uses Http nodejs library (by default)https: This adapter uses Https nodejs library
gpx: format result using GPX formatstring: format result to an String array (you need to specifyextra.formatterPatternkey)%Pcountry%pcountry code%nstreet number%Sstreet name%zzip code%TState%tstate code
You can improve this project by adding new geocoders or http adapters.
To run tests just npm test
To check code style install jshint and just run jshint lib test
You can add new geocoders by implementing the two method geocode & reverse:
var geocoder = {
geocode: function(value, callback) { },
reverse: function(lat, lng, callback) { }
}You can also add formatter implementing this interface
var formatter = {
format: function(data) { return formattedData; },
}