US Zip Codes / Cities - Distance / Info / Radius
Simple package for all US Zip Codes and Cities, get the distance between Zip Codes or Cities, get relevant information such as coordinates, cities within Zip Codes, Zip Codes covered by cities, states etc, get all the Zip Codes within certain radius and more.
Install
npm i zipcode-city-distance
Usage
const zipCodeData = require('zipcode-city-distance');
Zip Code Distance
let zipCodeDistance = zipCodeData.zipCodeDistance('98006', '33014','M');
2710.6371929140273
City Distance
without state parameters:
let cityDistance = zipCodeData.cityDistance('miami lakes', 'los angeles', 'M');
[ { place1: { city: 'Miami Lakes', state: 'FL', zipcode: [ '33014', '33016', '33018' ] },
place2: { city: 'Los Angeles', state: 'TX', zipcode: [ '78580' ] },
distance: 1082.6193359144372 },
{ place1: { city: 'Miami Lakes', state: 'FL', zipcode: [ '33014', '33016', '33018' ] },
place2: { city: 'Los Angeles', state: 'CA', zipcode: [ '90001','90002', ... more zipcodes here ... ,'91607','91608'] },
distance: 2333.4166337302295 } ]
with state parameters:
let cityDistance = zipCodeData.cityDistance('miami lakes', 'los angeles', 'M', 'FL', 'TX');
[ { place1: { city: 'Miami Lakes', state: 'FL', zipcode: [ '33014', '33016', '33018' ] },
place2: { city: 'Los Angeles', state: 'TX', zipcode: [ '78580' ] },
distance: 1082.6193359144372 } ]
Zip Code Info
let zipInfo = zipCodeData.getInfo('zipcode', '98006');
{
"message": "completed your request",
"data": {
"state":"WA",
"location": {
"lat": 47.557627,
"lon": -122.151005,
},
"places": {
"Bellevue": {
"location": {
"lat": 47.597837,
"lon": -122.15648
}
},
"Newcastle": {
"location": {
"lat": 47.531664,
"lon": -122.165566
}
}
}
}
}
City Info
let zipInfo = zipCodeData.getInfo('city', 'lakemont');
{ message: 'completed your request',
data:
[ { lat: 40.465434,
lon: -78.391752,
state: 'PA',
zipCode: ["16602","16648"]
} ]
}
Zip Code Radius
Get all zipcodes within a radius of this zipcode in ascending order.
[ { zipcode: '98056', distance: 3.613853931442833 },
{ zipcode: '98040', distance: 3.765403793043263 },
{ zipcode: '98007', distance: 3.89502983948142 },
{ zipcode: '98005', distance: 4.018115501775772 },
{ zipcode: '98008', distance: 4.099796739847524 },
{ zipcode: '98059', distance: 4.449603369443228 },
{ zipcode: '98004', distance: 4.899415818312604 } ]
TODO:
- add radius functionality for cities.
- add international functionality
- add a bug tracker
- add data links.
Like it here:
https://github.com/buddyeorl/zipcode-city-distance-pkg