RE: [PHP] zip codes and lat/longs
| From: | Jay Blanchard | Date: | Thu, 06 Dec 2007 16:11:53 +0000 |
| Subject: | RE: [PHP] zip codes and lat/longs | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-265508@lists.php.net to get a copy of this message | ||
[snip]
I'm entertaining how to determine what zip codes fall within a 50
mile radius of another zip code.
Anyone done this before?
Also, does anyone have any sources for zip codes and lat/long databases?
TIA for any help/suggestions.
[/snip]
Here is a code snip that I use to determine things within a certain
radius (5 miles) of a zip code;
/* calcs for distance */
function distance($lat1, $lon1, $lat2, $lon2) {
$theta = $lon1 - $lon2;
$dist = sin(deg2rad($lat1)) * sin(deg2rad($lat2)) +
cos(deg2rad($lat1)) * cos(deg2rad($lat2)) * cos(deg2rad($theta));
$dist = acos($dist);
$dist = rad2deg($dist);
$miles = $dist * 60 * 1.1515;