Created
January 22, 2015 20:23
-
-
Save kylehotchkiss/57f9707f41ac33ebe505 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var request = require("request"); | |
var first = 10001; | |
var last = 99999; | |
var current = first; | |
var zips = {}; | |
var convertZip = (function convertZip() { | |
if ( current < last ) { | |
var url = "http://maps.googleapis.com/maps/api/geocode/json?address=" + current + "+usa&sensor=false"; | |
request( url, function( error, response, body ) { | |
var content = JSON.parse( body ); | |
if ( content.results[0] ) { | |
if ( content.results[0].address_components[0].types[0] === "postal_code" ) { | |
var coords = content.results[0].geometry.location; | |
var lat = coords.lat; | |
var lng = coords.lng; | |
console.log( current + " " + lat + " " + lng ); | |
zips[current] = { lat: lat, lng: lng } ; | |
} else { | |
//console.log( content ); | |
} | |
} | |
current++; convertZip(); | |
}); | |
} else { | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment