Get zip code from latitude, longitude?

Consider the GeoNames web service. It’s a complete geocoding/reverse geocoding suite under a Creative Commons attribution license. You can either download their data, or hit their web service. The best thing is, they don’t require any API keys or licensing silliness–you just hit their web app and bang you got data.

Here’s an example: http://ws.geonames.org/findNearbyPostalCodesJSON?formatted=true&lat=36&lng=-79.08 That’ll return you a JSON object for the zip codes around the Chapel Hill, NC area.

It’s also international. Here’s Seaford, England, and the only difference is the lat/lng pair I’m sending: http://ws.geonames.org/findNearbyPostalCodesJSON?formatted=true&lat=50.5&lng=0.08

Then you need to learn to make web requests and parse JSON (if you don’t already have a grip on those things), and you’re all set.

Leave a Comment