开发者社区> 镜像站> NPM> us-zips
us-zips
A list of US ZIP codes and their geolocations
Last updated 7 months ago by blakek .
MIT · Repository · Original npm · Tarball · package.json
$ cnpm install us-zips 
SYNC missed versions from official npm registry.

us-zips

A list of US ZIP codes and their geolocations

I needed a list of ZIP codes, and the US Census Bureau had one.

Usage

Example: get the nearest zip to a geolocation

const geolib = require('geolib');
const usZips = require('us-zips');

const somewhere = {
  lat: 33.1234,
  lng: -88.4321
};

geolib.findNearest(somewhere, usZips); // { distance: 12834, key: '39341' }

If you want to get the nearest ZIP, see if geo2zip fits your needs.

Data Formats

Default (Object)

The default export returns an object. The object's keys are each ZIP code and values are objects with latitude and longitude properties.

const usZips = require('us-zips')

console.log(usZips['54301'])
// { latitude: 44.480778, longitude: -88.016063 }

// Shape
{
  '54301': {
    latitude: 44.480778,
    longitude: -88.016063
  }
}

Array

const usZips = require('us-zips/array')

console.log(usZips.find(zip => zip.zipCode === '37214'))
// { latitude: 36.162189, longitude: -86.670867, zipCode: '37214' }

// Shape
[
  ...
  {
    latitude: 36.162189,
    longitude: -86.670867,
    zipCode: '37214'
  },
  ...
]

Key/value

const usZips = require('us-zips/key-value')

console.log(usZips.find(([key, value]) => key === '10001'))
// ['10001', { latitude: 40.750634, longitude: -73.997176 }]

// Shape
[
  ...
  ['10001', {
    latitude: 40.750634,
    longitude: -73.997176
  }],
  ...
]

Map

const usZips = require('us-zips/map');

console.log(usZips.get('90210'));
// { latitude: 34.100517, longitude: -118.41463 }

Install

With Yarn or npm installed, run:

yarn add us-zips

# ...or, if using `npm`
npm install us-zips

Acknowledgments

Data for ZIP codes and their geolocations was generated from this file, which can be downloaded from the US Census Bureau map data page.

See Also

License

MIT

Current Tags

  • 4.0.2                                ...           latest (7 months ago)

9 Versions

  • 4.0.2                                ...           7 months ago
  • 4.0.1                                ...           10 months ago
  • 4.0.0                                ...           a year ago
  • 3.0.1                                ...           a year ago
  • 3.0.0                                ...           2 years ago
  • 2.0.2                                ...           3 years ago
  • 2.0.1                                ...           3 years ago
  • 2.0.0                                ...           4 years ago
  • 1.0.0                                ...           4 years ago
Maintainers (1)
Downloads
Today 0
This Week 1
This Month 1
Last Day 0
Last Week 0
Last Month 1
Dependencies (0)
None
Dev Dependencies (1)