4.4.0 • Published 3 months ago

node-geocoder v4.4.0

Weekly downloads
67,134
License
MIT
Repository
github
Last release
3 months ago

node-geocoder

Test 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

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

const options = {
  provider: 'google',

  // Optional depending on the providers
  fetch: customFetchImplementation,
  apiKey: 'YOUR_API_KEY', // for Mapquest, OpenCage, APlace, Google Premier
  formatter: null // 'gpx', 'string', ...
};

const geocoder = NodeGeocoder(options);

// Using callback
const res = await geocoder.geocode('29 champs elysée paris');

// 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)

const res = await geocoder.geocode({
  address: '29 champs elysée',
  country: 'France',
  zipcode: '75008'
});

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

// Reverse example

const res = await geocoder.reverse({ lat: 45.767, lon: 4.833 });

// Batch geocode

const results = await geocoder.batchGeocode([
  '13 rue sainte catherine',
  'another address'
]);

// Set specific http request headers:
const nodeFetch = require('node-fetch');

const geocoder = NodeGeocoder({
  provider: 'google',
  fetch: function fetch(url, options) {
    return nodeFetch(url, {
      ...options,
      headers: {
        'user-agent': 'My application <email@domain.com>',
        'X-Specific-Header': 'Specific value'
      }
    });
  }
});

Geocoder Providers (in alphabetical order)

  • agol : ArcGis Online Geocoding service. Supports geocoding and reverse. Requires a client_id & client_secret
  • aplace : APlace.io Geocoding service. Supports geocoding and reverse. Requires an access token (read about access tokens here) using options.apiKey
    • For geocode you can use simple string parameter or an object containing the different parameters (type, address, zip, city, country, countryCode and countries). See available values for type and countries parameters here
    • For reverse, you can pass over {lat, lon}
    • For both methods, use options.language (either fr or en) to specify the language of the results
  • datasciencetoolkit : DataScienceToolkitGeocoder. Supports IPv4 geocoding and address geocoding. Use options.host to specify a local instance
  • freegeoip : FreegeoipGeocoder. Supports IP geocoding
  • geocodio: Geocodio, Supports address geocoding and reverse geocoding (US only)
  • 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.
  • here : HereGeocoder. Supports address geocoding and reverse geocoding. You must specify options.apiKey with your Here API key. You can also use options.language, options.politicalView (read about political views here), options.country, and options.state.
  • 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 the different 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!
  • mapbox : MapBoxGeocoder. Supports address geocoding and reverse geocoding. Needs an apiKey
  • mapquest : MapQuestGeocoder. Supports address geocoding and reverse geocoding. Needs an apiKey
  • nominatimmapquest: Same geocoder as openstreetmap, but queries the MapQuest servers. You need to specify options.apiKey
  • opencage: OpenCage Geocoder. Aggregates many different open geocoder. Supports address and reverse geocoding with many optional parameters. You need to specify options.apiKey which can be obtained at OpenCage.
  • opendatafrance: OpendataFranceGeocoder supports forward and reverse geocoding in France; for more information, see OpendataFrance API documentation
  • openmapquest : Open MapQuestGeocoder (based on OpenStreetMapGeocoder). Supports address geocoding and reverse geocoding. Needs an apiKey
  • 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.
  • pickpoint: PickPoint Geocoder. Supports address geocoding and reverse geocoding. You need to specify options.apiKey obtained at PickPoint.
    • 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.
  • smartyStreet: Smarty street geocoder (US only), you need to specify options.auth_id and options.auth_token
  • teleport: Teleport supports city and urban area forward and reverse geocoding; for more information, see Teleport API documentation
  • tomtom: TomTomGeocoder. Supports address geocoding. You need to specify options.apiKey and can use options.language to specify a language
  • virtualearth: VirtualEarthGeocoder (Bing maps). Supports address geocoding. You need to specify options.apiKey
  • yandex: Yandex support address geocoding, you can use options.language to specify language

Fetch option

With the options.fetch you can provide your own method to fetch data. This method should be compatible with the Fetch API.

This allow you to specify a proxy to use, a custom timeout, specific headers, ...

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:

const 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

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

Contributing

You can improve this project by adding new geocoders.

To run tests just npm test.

To check code style just run npm run lint.

@pubngo-stack/property-module-servercountry-data-adclickersbotclient-ip-infoospoon-merchant@ilmtest/salat10-sdk@happyincent/ig-uploadboilerplate-hapijs@infinitebrahmanuniverse/nolb-node-gthing-it-server@everything-registry/sub-chunk-2303breinstormin.mongo.kernelfoo-toolsfutura_utilitiesjarvis-botjustshare-componentsjustshareapiioc-apilcommithoshistech-libhubot-isshubot-what3wordshubot-time-memax-chatbotmediumroast_jsmf-geocodemindscape.iomuch-boxnode-geocoder-clinode-geolocationnode-geocachernode-geolocalisationnode-get-lat-lngnode-uber-gmapsnpm-core-authorizepepe-distcalcorderio-test-rowy-commonjessica-aiiphone-availability-cliloqate-geocodermaia-db-liblandrnacweb-utility-componentsnepremicnine-web-scraper@iannjuguna/tumanaapi@mediocre/bloodhound@kalisio/geokoder@kalisio/kdk-map@kibibit/kibibedmapdolphin-libecholocatedcrwexpress-geocoding-apieschr-libpokespotterpokegopolygonifierpcmli.umbrella.backendyourttoo.kernel.exodusreal-random-addressrotating-geocoderresponse-libraryresponse-library-developmentresponse-library-prodresponse-library-productionresponse-library1sails-service-locationreverse-geocode-csvsimple-reverse-geocoderspidergraphsiftttsurgersoss-clithe-pharmacist-delivers@cheio/node-geolocation@christian-nja/geocodingweatherdesttwitter-trends-by-locationuberjs10bis10bisjs@goodcastle/api-plugin-shipments@egodigital/egoose@emigrup/edk-map@troyaaronjones/bloodhoundaddress-to-geocodeadonis-geocoderbutler-weatherbackend_crud-api-nodejs-expressjs-mongodbcreate-reaction-appcsv-to-kmldataviz-tangibleclient-response-librariesclient-response-libraryclient-response-library1apostrophe-mapapp-service-paltform-exchangeahj-scope@panda-clouds/geocoder@mosich/gettheweather
4.4.0

3 months ago

4.3.0

9 months ago

4.2.0

2 years ago

4.1.0

2 years ago

4.0.0

3 years ago

3.29.0

3 years ago

3.28.0

3 years ago

3.27.0

5 years ago

3.26.0

5 years ago

3.25.1

5 years ago

3.25.0

5 years ago

3.24.0

5 years ago

3.23.0

5 years ago

3.22.0

7 years ago

3.21.1

7 years ago

3.21.0

7 years ago

3.20.1

7 years ago

3.20.0

7 years ago

3.19.0

7 years ago

3.18.0

7 years ago

3.17.0

7 years ago

3.16.0

8 years ago

3.15.2

8 years ago

3.15.1

8 years ago

3.15.0

8 years ago

3.14.0

8 years ago

3.13.1

8 years ago

3.13.0

8 years ago

3.12.0

8 years ago

3.11.0

8 years ago

3.10.0

8 years ago

3.9.1

9 years ago

3.9.0

9 years ago

3.8.0

9 years ago

3.7.0

9 years ago

3.6.2

9 years ago

3.6.1

9 years ago

3.6.0

9 years ago

3.5.1

9 years ago

3.5.0

9 years ago

3.4.1

9 years ago

3.4.0

9 years ago

3.3.0

9 years ago

3.2.0

9 years ago

3.1.0

9 years ago

3.0.2

9 years ago

3.0.1

9 years ago

3.0.0

9 years ago

2.23.0

9 years ago

2.22.0

9 years ago

2.21.2

9 years ago

2.21.1

9 years ago

2.21.0

9 years ago

2.20.2

9 years ago

2.20.1

9 years ago

2.20.0

10 years ago

2.19.2

10 years ago

2.19.1

10 years ago

2.19.0

10 years ago

2.18.2

10 years ago

2.18.1

10 years ago

2.18.0

10 years ago

2.17.1

10 years ago

2.17.0

10 years ago

2.16.1

10 years ago

2.16.0

10 years ago

2.15.1

10 years ago

2.15.0

10 years ago

2.14.0

10 years ago

2.13.4

10 years ago

2.13.3

10 years ago

2.13.2

10 years ago

2.13.1

10 years ago

2.13.0

10 years ago

2.12.1

10 years ago

2.12.0

10 years ago

2.11.1

10 years ago

2.11.0

10 years ago

2.10.0

10 years ago

2.9.2

10 years ago

2.9.1

10 years ago

2.9.0

10 years ago

2.8.2

10 years ago

2.8.1

10 years ago

2.8.0

10 years ago

2.7.1

10 years ago

2.7.0

10 years ago

2.6.0

10 years ago

2.5.3

10 years ago

2.5.2

10 years ago

2.5.1

10 years ago

2.5.0

10 years ago

2.4.1

10 years ago

2.4.0

10 years ago

2.3.0

10 years ago

2.2.0

11 years ago

2.1.1

11 years ago

2.1.0

11 years ago

2.0.1

11 years ago

2.0.0

11 years ago

1.4.0

11 years ago

1.3.0

11 years ago

1.2.0

11 years ago

1.1.0

11 years ago

1.0.3

11 years ago

1.0.2

11 years ago

1.0.1

11 years ago

1.0.0

11 years ago

0.7.0

11 years ago

0.6.0

11 years ago

0.5.0

11 years ago

0.4.0

11 years ago

0.3.0

11 years ago

0.2.0

11 years ago

0.1.0

11 years ago

0.0.5

11 years ago

0.0.4

11 years ago

0.0.3

11 years ago

0.0.2

11 years ago

0.0.1

11 years ago