Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm's 300,000 packages pre-installed, including node-geocoder-ca with all npm packages installed. Try it out:

var nodeGeocoderCa = require("node-geocoder-ca")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

node-geocoder-ca v0.1.2

Node.js module to interface with the Geocoder.ca API

Geocoder.ca Module

Node.js module to interface with the Geocoder.ca API. Build Status

Usage

Accepts a location argument and a callback. callback receives two params: err and coords. In the case of an error, err will contain an Error object. Otherwise, coords will be populated with a Coords object, with lat and lon properties.

location can be one of the following:

  • a String with location (eg. __"525 Market St, Philadelphia, PA 19106"__)
  • a String with a zip/postal code (eg. "19106" or __"M4A 2L7"__)
  • a Number with a 5-digit zip code (eg. 19106)
  • an Object containing one of the following:
    • a single locate property containing one of the above
    • a single postal propery containing a zip or postal code
    • the following four properties: addresst, stno, city, and prov

If location is an object, it is converted to a query string and passed directly to the Geocoder.ca API. See API docs for parameters.

Example

var Geocoder = require('node-geocoder-ca').Geocoder,
    geocoder = new Geocoder(),
    address = '525 Market St, Philadelphia, PA 19106';

geocoder.geocode(address, function(err, coords) {
    if (err) {
        throw err;
    }

    console.log("%s geocoded to [%d, %d]", address, coords.lat, coords.lon);
});

Events

The Geocoder object is an event emitter. It emits the following events:

  • A result event happens whenever geocoding succeeds. It passes a Coords object to any listeners.
  • A error event happens whenever there is an error. It passes the Error object to any listeners.

You can choose to skip the callback on the geocode() method and listen for events instead.

Warning: this usage is currently untested.

Example:

var Geocoder = require('node-geocoder-ca').Geocoder,
    geocoder = new Geocoder(),
    address = '525 Market St, Philadelphia, PA 19106';

geocoder.geocode(address)
    .on('result', function(coords) { /* ... */ })
    .on('error', function(err) { /* ... */ });

Todo

  • [x] Basic geocoding
  • [ ] Suggestions on failed geocoding
  • [ ] Reverse geocoding
  • [ ] Tests for event-based usage

Metadata

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free