npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

bardak-dev-geoceder

v3.22.0

Published

Node Geocoder, node geocoding library, supports google maps, mapquest, open street map, tom tom, promise

Downloads

12

Readme

node-geocoder

Build Status Dependencycy status npm version

Node library for geocoding and reverse geocoding. Can be used as a nodejs library

Installation (nodejs library)

npm install node-geocoder

Usage example

var NodeGeocoder = require('node-geocoder');

var options = {
  provider: 'google',

  // Optional depending on the providers
  httpAdapter: 'https', // Default
  apiKey: 'YOUR_API_KEY', // for Mapquest, OpenCage, Google Premier
  formatter: null         // 'gpx', 'string', ...
};

var geocoder = NodeGeocoder(options);

// 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',
  administrativeLevels: {
    level1long: 'Île-de-France',
    level1short: 'IDF',
    level2long: 'Paris',
    level2short: '75'
  },
  provider: 'google'
}]

Advanced usage (only google, here, mapquest, locationiq, and opencage providers)

geocoder.geocode({address: '29 champs elysée', country: 'France', zipcode: '75008'}, function(err, res) {
  console.log(res);
});

// OpenCage advanced usage example
geocoder.geocode({address: '29 champs elysée', countryCode: 'fr', minConfidence: 0.5, limit: 5}, function(err, res) {
  console.log(res);
});

// Reverse example

// Using callback
geocoder.reverse({lat:45.767, lon:4.833}, function(err, res) {
  console.log(res);
});

// Or using Promise
geocoder.reverse({lat:45.767, lon:4.833})
  .then(function(res) {
    console.log(res);
  })
  .catch(function(err) {
    console.log(err);
  });

// Batch geocode

geocoder.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:
var HttpsAdapter = require('node-geocoder/lib/httpadapter/httpsadapter.js')
var httpAdapter = new HttpsAdapter(null, {
  headers: {
    'user-agent': 'My application <[email protected]>',
    'X-Specific-Header': 'Specific value'
  }
});

var geocoder = NodeGeocoder({
  provider: 'google',
  httpAdapter: httpAdapter
});

Geocoder Provider

  • google : GoogleGeocoder. Supports address geocoding and reverse geocoding. Use options.clientIdand options.apiKey(privateKey) for business licence. You can also use options.language and options.region to specify language and region, respectively. Note that 'https' is required when using an apiKey
  • here : HereGeocoder. Supports address geocoding and reverse geocoding. You must specify options.appId and options.appCode with your license keys. You can also use options.language, options.politicalView (read about political views here), options.country, and options.state.
  • freegeoip : FreegeoipGeocoder. Supports IP geocoding
  • datasciencetoolkit : DataScienceToolkitGeocoder. Supports IPv4 geocoding and address geocoding. Use options.host to specify a local instance
  • openstreetmap : OpenStreetMapGeocoder. Supports address geocoding and reverse geocoding. You can use options.language and options.email to 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-agent or referrer header field as required by https://wiki.openstreetmap.org/wiki/Nominatim_usage_policy
    • Set options.osmServer to use custom nominatim server. Example: you can setup local nominatim server from instructions at this page and set options.osmServer: http://localhost:8000 to use local server.
  • locationiq : LocationIQGeocoder. Supports address geocoding and reverse geocoding just like openstreetmap but does require only a locationiq api key to be set.
    • For geocode you can use simple q parameter 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!
  • mapquest : MapQuestGeocoder. Supports address geocoding and reverse geocoding. Needs an apiKey
  • openmapquest : Open MapQuestGeocoder (based on OpenStreetMapGeocoder). Supports address geocoding and reverse geocoding. Needs an apiKey
  • agol : ArcGis Online Geocoding service. Supports geocoding and reverse. Requires a client_id & client_secret and 'https' http adapter
  • tomtom: TomTomGeocoder. Supports address geocoding. You need to specify options.apiKey
  • virtualearth: VirtualEarthGeocoder (Bing maps). Supports address geocoding. You need to specify options.apiKey
  • nominatimmapquest: Same geocoder as openstreetmap, but queries the MapQuest servers. You need to specify options.apiKey
  • opencage: OpenCage Geocoder. Uses multiple open sources. Supports address and reverse geocoding. You need to specify options.apiKey
  • smartyStreet: Smarty street geocoder (US only), you need to specify options.auth_id and options.auth_token
  • geocodio: Geocodio, Supports address geocoding and reverse geocoding (US only)
  • yandex: Yandex support address geocoding, you can use options.language to specify language
  • teleport: Teleport supports city and urban area forward and reverse geocoding; for more information, see Teleport API documentation
  • opendatafrance: OpendataFranceGeocoder supports forward and reverse geocoding in France; for more information, see OpendataFrance API documentation
  • pickpoint: PickPoint Geocoder. Supports address geocoding and reverse geocoding. You need to specify options.apiKey obtained at PickPoint. https is required.
    • As parameter for geocode function you can use a string representing an address like "13 rue sainte catherine" or an object with parameters described in Forward Geocoding Reference.
    • For geocode function you should use an object where {lat, lon} are required parameters. Additional parameters like zoom are available, see details in Reverse Geocoding Reference.

Http adapter

  • https: This adapter uses the Https nodejs library (default)
  • http: This adapter uses the Http nodejs library
  • request: This adapter uses the request nodejs library

You can specify request timeout using paramater options.timeout

Formatter

  • gpx : format result using GPX format
  • string : format result to an String array (you need to specify options.formatterPattern key)
    • %P country
    • %p country code
    • %n street number
    • %S street name
    • %z zip code
    • %T State
    • %t state code
    • %c City

More

Playground

You can try node-geocoder here http://node-geocoder.herokuapp.com/

Command line tools

node-geocoder-cli You can use node-geocoder-cli to geocode in shell

Extending node geocoder

You can add new geocoders by implementing the two methods geocode and reverse:

var geocoder = {
    geocode: function(value, callback) { ... },
    reverse: function(query, callback) { var lat = query.lat; var lon = query.lon; ... }
}

You can also add formatter implementing the following interface

var formatter = {
    format: function(data) { return formattedData; },
}

Contributing

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.