Code Monkey home page Code Monkey logo

geocoder-arcgis's Introduction

GeocoderArcGIS npm version

A promises based JavaScript wrapper for the ArcGIS Geocoder API. It uses fetch-everywhere to use in

  • Node
  • Browser
  • React-native

Installation

Installing using npm:

npm i geocoder-arcgis -S

Usage

Initialization

const GeocoderArcGIS = require('geocoder-arcgis');

const geocoder = new GeocoderArcGIS({
  client_id: 'YOUR CLIENT ID',         // optional, see below
  client_secret: 'YOUR CLIENT SECRET'  // optional, see below
});

The constructor function also takes an optional configuration object:

  • client_id: id for OAuth to use with "geocodeAddresses" or "forStorage" option. See reference
  • client_secret: secret for OAuth to use with "geocodeAddresses" or "forStorage" option. See reference
  • endpoint: custom ArcGIS endpoint

Geocode (findAddressCandidates)

geocoder.findAddressCandidates('380 New York Street, Redlands, CA 92373',{})
    .then((result) =>{
      console.log(result);
    })
    .catch(console.log);

You can pass a SingleLine string or an object to the geocoder.

Optional parameters:

Reverse geocode (reverseGeocode)

geocoder.reverse('51.484463,-0.195405',{ // longitude,latitude
  maxLocations: 10,
  distance: 100
}).then((result) => {
  console.log(result);
});

Optional parameters:

Suggest (suggest)

geocoder.suggest('Glogauer Straße, Berlin',{})
.then((result) => {
  console.log(result);
})
.catch(console.log);

Optional parameters:

geocodeAddresses

geocoder.geocodeAddresses([
  "380 New York St., Redlands, CA, 92373",
  {
    "Address": "1 World Way",
    "Neighborhood": "",
    "City": "Los Angeles",
    "Subregion": "",
    "Region": "CA"
  }
  ],{})
    .then((result){
      console.log(result);
    })
    .catch(console.log);

You can pass an array of attributes to the geocoder. All required fields will be added/formatted automatically. If you don't pass in OBJECTIDs for each address, this library will create them for you. You can pass a SingleLine string or an object to the geocoder.

Optional parameters:

Geocode (find) - deprecated

geocoder.geocode('Berlin',{})
    .then((response) => {
        console.log(response);
    })
    .catch(console.log);

Response

All methods return a promise.

See Also

  • geoservices-js provides another client for the ArcGIS geocoder, using a callback interface instead of promises.

geocoder-arcgis's People

Contributors

evansiroky avatar jgravois avatar markstos avatar timoruetten avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

geocoder-arcgis's Issues

wish: implement authentication caching

The current design re-authenticates for every request that requires it.

It would improve performance if re-authentication only happened if the original authentication token has expired.

I believe ESRI's geoservices-js implements this if a reference is helpful for implementing this.

Wish: support filtering geocoding to a bounding box.

It would be nice if there was an option to specify a bounding box to be used with geocoding, so that results outside the bounding box would be considered geocode failures.

I did not find this feature documented as being in the ArcGIS online gecoder, so it needs to be implemented now in client libraries.

This library could perhaps use coordinatesContainsPoint to check results as they come back.

Add custom endpoints

The default endpoint is https://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer/. When I run my own service, the endpoints are

http://<catalog-url>/<serviceName>/GeocodeServer

suggest: http://geocodeservice-url/suggest
findAddressCandidates: http://<geocodeservice-url>/findAddressCandidates
reverseGeocode: http://<geocodeservice-url>/reverseGeocode
geocodeAddresses: http://<geocodeservice-url>/geocodeAddresses

And find is the same like geocodeAddresses ?

Would you guys @jgravois @markstos please clarify?

wish: implement geocodeAddresses

The bulk geocode method 'geocodeAddresses' is documented to exist, but there are no tests for it, and the code to construct the proper query seems to be missing. A manual test of the example shown in the README returned a 200.

Also, the method is designed for /bulk/ geocoding, yet the example showed passing only a single string to the method. I would presume an array would be accepted.

There may be some code of interest to borrow from geoservices-js which has a working client for this REST endpoint.

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.