Coder Social home page Coder Social logo

node-geocoder's Introduction

node-geocoder

Build Status

Node library for geocoding and reverse geocoding. Can be used as a nodejs library or on command line

Installation and usage (geocoder command line)

npm install -g node-geocoder
geocoder --provider google 'Fornino, 187 Bedford Ave, Brooklyn, NY 11211'

Installation (nodejs library)

npm install node-geocoder

Usage example

var geocoderProvider = 'google';
var httpAdapter = 'http';
// optionnal
var extra = {
    apiKey: 'YOUR_API_KEY', // for Mapquest, OpenCage, 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'
}]

## Advanced 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);
    });

Geocoder Provider

  • google : GoogleGeocoder. Supports address geocoding and reverse geocoding. Use extra.clientIdand extra.apiKey(privateKey) for business licence. You can also use extra.language and extra.region to specify language and region, respectively. Note that 'https' is required when using an apiKey
  • freegeoip : FreegeoipGeocoder. Supports IP geocoding
  • datasciencetoolkit : DataScienceToolkitGeocoder. Supports IPv4 geocoding and address geocoding. Use extra.host to specify a local instance
  • openstreetmap : OpenStreetMapGeocoder. Supports address geocoding and reverse geocoding
  • 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
  • tomtom: TomTomGeocoder. Supports address geocoding. You need to specify extra.apiKey
  • nominatimmapquest: OpenStreetMap Nominatim geocoder. Support address and reverse geocoding
  • opencage: OpenCage Geocoder. Uses multiple open sources. Supports address and reverse geocoding. You need to specify extra.apiKey
  • smartyStreet: Smarty street geocoder (US only), you need to specify extra.auth_id and extra.auth_token

Http adapter

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

Formatter

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

More

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.

Extending node geocoder

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

var geocoder = {
    geocode: function(value, callback) { },
    reverse: function(lat, lng, callback) { }
}

You can also add formatter implementing the following interface

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

node-geocoder's People

Contributors

aaronjudd avatar brandonaaron avatar chanced avatar cmwelsh avatar danasf avatar delianides avatar dmarg avatar jonnybgod avatar keeganlow avatar mtmail avatar nchaulet avatar nisaacson avatar pawelrychlik avatar rodrigok avatar skimmmer avatar timothyquach avatar xta avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.