mrt:zipcodes

v0.0.1Published 10 years ago

This package has not had recent updates. Please investigate it's current state before committing to using it in your project.

Zip Code Lookups

Installation

mrt add zipcodes

A localized (flatfile) zipcode lookup.

Zipcode data was taken from here: http://federalgovernmentzipcodes.us/

It was then transformed into a JSON object and then wrapped with some helper methods.

Zipcode Lookup

var hills = Zipcodes.lookup(90210);

{ zip: '90210',
  latitude: 34.088808,
  longitude: -118.406125,
  city: 'Beverly Hills',
  state: 'CA' }

Distance

This is not driving distance, it's line of sight distance

var dist = Zipcodes.distance(62959, 90210); //In Miles
// dist = 1662

var kilo = Zipcodes.toKilometers(dist); //Convert to Kilometers
// kilo = 2675

var miles = Zipcodes.toMiles(zipcodes.toKilometers(dist)); //Convert to Kilometers, then to miles
// miles = 1662

Lookup By Name

var l = Zipcodes.lookupByName('Cupertino', 'CA');

//Always returns an array, since cities can have multiple zip codes
[ { zip: '95015',
    latitude: 37.323,
    longitude: -122.0527,
    city: 'Cupertino',
    state: 'CA' } ]

Lookup by Radius

Get all zipcodes within the milage radius of this zipcode

var rad = Zipcodes.radius(95014, 50);
// rad.length == 385

[ '93901',
  '93902',
  '93905',
  '93906',
  '93907',
  '93912',
  '93933',
  '93942',
  '93944',
  '93950',
  ...
  '95377',
  '95378',
  '95385',
  '95387',
  '95391'
]