Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Node.js API that converts gps coordinate pairs to US zip codes

branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 bin
Octocat-spinner-32 public
Octocat-spinner-32 views
Octocat-spinner-32 .gitignore
Octocat-spinner-32 .npmignore
Octocat-spinner-32 LICENSE
Octocat-spinner-32 Readme.md
Octocat-spinner-32 demo.js
Octocat-spinner-32 package.json
Octocat-spinner-32 server.js
Octocat-spinner-32 zips.csv
Octocat-spinner-32 zips.json
Readme.md

Gps2zip

Convert GPS latitude longitude pairs to a US zip code.

Runs as a server-side node API for your client-side js applications.

Quick Start

npm install Gps2zip
cd node_modules/Gps2zip/
node demo.js

Example usage of demo app

Start the demo app

node demo.js

Access the REST API with curl:

burt$ curl "localhost:4000?lat=30.2859283&lon=-97.7461031"
{
    "zip code":"78705",
    "state abbreviation":"TX",
    "latitude":" 30.292424",
    "longitude":" -97.73856",
    "city":"Austin",
    "state":"Texas",
    "distance":0.009954520385227613
}

Or from jQuery:

var lat = 30.2859283;
var lon = -97.7461031;
$.get("/?lat=" + lat + "&lon=" + lon, function(res){
    console.log(res);
    if(res.error != undefined){
        console.log(res.error);
    } else {
        console.log(res["zip code"]);
    }
});

Open /demo in the browser for a more user-friendly demo.

Using gps2zip in your own application

var gps = require('gps2zip');
var latitude = '30.2669';
var longitude = '97.7428';
var response = gps.gps2zip(latitude, longitude);
console.log(response); //78701

Accuracy

The output is approximate. The source data is just a list of coordinates, not actual boundaries. The algorithm just finds the minimum euclidean distance between the point in question and the known points. No error checking for points outside the United States.

Related

You can get full street addresses using the Google Maps Reverse Geocoding API: http://code.google.com/apis/maps/documentation/javascript/geocoding.html#ReverseGeocoding

Credit

Zip codes from The Zip Code Database Project http://sourceforge.net/projects/zips/

License

All other work is The Unlicense (Public Domain)

Something went wrong with that request. Please try again.