[nycphp-talk] Zipcodes calculation
Rolan Yang
rolan at omnistep.com
Sun Jul 18 20:37:57 EDT 2004
Kshitij Bedi wrote:
>I have a database with zipcodes and corresponding latitudes and longitudes.
>Can anyone suggest a mysql statement that can pull me all zipcodes within 20
>or 50 or 100 miles of a given zipcode
>
>Kshitij Bedi
>
>
I did something like that a long time ago. Digging through my perl code,
I found this:
$ratio=0.0147791915; # miles per degree lattitude
Since the area that a zip code covers is somewhat of a fuzzy value, a
reasonable estimate would be to use something like this:
$dist=$miles*$ratio;
$query='select zipcodes from yourdatabase where
lat>'.($currentlat-$dist).' and lat<'.($currentlat+$dist).' and
lon>'.($currentlon-$dist).' and lon<'.($currentlon+$dist)';
you should obviuosly query the db beforehand to get the currentlat and
currentlon based on your selected zipcode.
~Rolan
More information about the talk
mailing list