NYCPHP Meetup

NYPHP.org

[nycphp-talk] Zip code radius

John Campbell jcampbell1 at gmail.com
Fri May 22 14:36:14 EDT 2009


I used to do a bit of GIS stuff.

Here is what you need to do.

1) Import a list of zip codes & lat/lng centroids into your database.
The data is here:
http://www.census.gov/tiger/tms/gazetteer/zips.txt

2) Geocode all of your contacts, and store the lat/lng coordinates
with the contacts. Google has a free geocoding service.  You need a
google api key, and they only allow 10,000 queries per day per IP.
Depending on how many contacts you have, this may take several days to
get all of the coordinates.
The docs are here:
http://code.google.com/apis/maps/documentation/geocoding/index.html

3) Read up on the Haversine formula.
http://en.wikipedia.org/wiki/Haversine_formula

Once you have these three pieces, you will be able to calculate the
distance between contacts and any zip code.

Regards,
John Campbell




On Fri, May 22, 2009 at 2:09 PM, Aaron Fischer <afischer at smith.edu> wrote:
> I'd like to build a feature that will allow someone to enter a zip and a
> radius and have the page display all the contacts that are within the
> specified radius of that location.  (I have a db table to query that has
> contacts and their address information, including zips.)
>
> Has anyone found a class or code that they like that will do this?
>
> Displaying results on a map would be a sweet bonus but is not required.
>
> -Aaron
> _______________________________________________
> New York PHP User Group Community Talk Mailing List
> http://lists.nyphp.org/mailman/listinfo/talk
>
> http://www.nyphp.org/show_participation.php
>



More information about the talk mailing list