Node library for geocoding and reverse geocoding. Can be used as a nodejs library
npm install node-geocoder
varNodeGeocoder=require('node-geocoder');varoptions={provider: 'google',// Optional depending on the providershttpAdapter: 'https',// DefaultapiKey: 'YOUR_API_KEY',// for Mapquest, OpenCage, Google Premierformatter: null// 'gpx', 'string', ...};vargeocoder=NodeGeocoder(options);// Using callbackgeocoder.geocode('29 champs elysée paris',function(err,res){console.log(res);});// Or using Promisegeocoder.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',administrativeLevels: {level1long: 'Île-de-France',level1short: 'IDF',level2long: 'Paris',level2short: '75'},provider: 'google'}]geocoder.geocode({address: '29 champs elysée',country: 'France',zipcode: '75008'},function(err,res){console.log(res);});// OpenCage advanced usage examplegeocoder.geocode({address: '29 champs elysée',countryCode: 'fr',minConfidence: 0.5,limit: 5},function(err,res){console.log(res);});// Reverse example// Using callbackgeocoder.reverse({lat:45.767,lon:4.833},function(err,res){console.log(res);});// Or using Promisegeocoder.reverse({lat:45.767,lon:4.833}).then(function(res){console.log(res);}).catch(function(err){console.log(err);});// Batch geocodegeocoder.batchGeocode(['13 rue sainte catherine','another adress'],function(err,results){// Return an array of type {error: false, value: []}console.log(results);});// Set specific http request headers:varHttpsAdapter=require('node-geocoder/lib/httpadapter/httpsadapter.js')varhttpAdapter=newHttpsAdapter(null,{headers: {'user-agent': 'My application <email@domain.com>','X-Specific-Header': 'Specific value'}});vargeocoder=NodeGeocoder({provider: 'google',httpAdapter: httpAdapter});google: GoogleGeocoder. Supports address geocoding and reverse geocoding. Useoptions.clientIdandoptions.apiKey(privateKey) for business licence. You can also useoptions.languageandoptions.regionto specify language and region, respectively. Note that 'https' is required when using an apiKeyhere: HereGeocoder. Supports address geocoding and reverse geocoding. You must specifyoptions.appIdandoptions.appCodewith your license keys. You can also useoptions.language,options.politicalView(read about political views here),options.country, andoptions.state.freegeoip: FreegeoipGeocoder. Supports IP geocodingdatasciencetoolkit: DataScienceToolkitGeocoder. Supports IPv4 geocoding and address geocoding. Useoptions.hostto specify a local instanceopenstreetmap: OpenStreetMapGeocoder. Supports address geocoding and reverse geocoding. You can useoptions.languageandoptions.emailto specify a language and a contact email address.- For
geocode, you can use an object as value, specifying one or several parameters from https://wiki.openstreetmap.org/wiki/Nominatim#Parameters - For
reverse, you can use additional parameters from https://wiki.openstreetmap.org/wiki/Nominatim#Parameters_2 - You should specify a specific
user-agentorreferrerheader field as required by https://wiki.openstreetmap.org/wiki/Nominatim_usage_policy - Set
options.osmServerto use custom nominatim server. Example: you can setup local nominatim server from instructions at this page and setoptions.osmServer: http://localhost:8000to use local server.
- For
locationiq: LocationIQGeocoder. Supports address geocoding and reverse geocoding just like openstreetmap but does require only a locationiq api key to be set.- For
geocodeyou can use simpleqparameter or an object containing th edifferent parameters defined here: http://locationiq.org/#docs - For
reverse, you can pass over{lat, lon}and additional parameters defined in http://locationiq.org/#docs - No need to specify referer or email addresses, just locationiq api key, note that there are rate limits!
- For
mapquest: MapQuestGeocoder. Supports address geocoding and reverse geocoding. Needs an apiKeyopenmapquest: Open MapQuestGeocoder (based on OpenStreetMapGeocoder). Supports address geocoding and reverse geocoding. Needs an apiKeyagol: ArcGis Online Geocoding service. Supports geocoding and reverse. Requires a client_id & client_secret and 'https' http adaptertomtom: TomTomGeocoder. Supports address geocoding. You need to specifyoptions.apiKeyvirtualearth: VirtualEarthGeocoder (Bing maps). Supports address geocoding. You need to specifyoptions.apiKeynominatimmapquest: Same geocoder asopenstreetmap, but queries the MapQuest servers. You need to specifyoptions.apiKeyopencage: OpenCage Geocoder. Uses multiple open sources. Supports address and reverse geocoding. You need to specifyoptions.apiKeysmartyStreet: Smarty street geocoder (US only), you need to specifyoptions.auth_idandoptions.auth_tokengeocodio: Geocodio, Supports address geocoding and reverse geocoding (US only)yandex: Yandex support address geocoding, you can useoptions.languageto specify languageteleport: Teleport supports city and urban area forward and reverse geocoding; for more information, see Teleport API documentationopendatafrance: OpendataFranceGeocoder supports forward and reverse geocoding in France; for more information, see OpendataFrance API documentationpickpoint: PickPoint Geocoder. Supports address geocoding and reverse geocoding. You need to specifyoptions.apiKeyobtained at PickPoint.httpsis required.- As parameter for
geocodefunction you can use a string representing an address like "13 rue sainte catherine" or an object with parameters described in Forward Geocoding Reference. - For
geocodefunction you should use an object where{lat, lon}are required parameters. Additional parameters likezoomare available, see details in Reverse Geocoding Reference.
- As parameter for
https: This adapter uses the Https nodejs library (default)http: This adapter uses the Http nodejs libraryrequest: This adapter uses the request nodejs library
You can specify request timeout using paramater options.timeout
gpx: format result using GPX formatstring: format result to an String array (you need to specifyoptions.formatterPatternkey)%Pcountry%pcountry code%nstreet number%Sstreet name%zzip code%TState%tstate code%cCity
You can try node-geocoder here http://node-geocoder.herokuapp.com/
node-geocoder-cli You can use node-geocoder-cli to geocode in shell
You can add new geocoders by implementing the two methods geocode and reverse:
vargeocoder={geocode: function(value,callback){ ... },reverse: function(query,callback){varlat=query.lat;varlon=query.lon; ... }}You can also add formatter implementing the following interface
varformatter={format: function(data){returnformattedData;},}You can improve this project by adding new geocoders or http adapters.
To run tests just npm test.
To check code style just run npm run lint.