beetle
10-31-2002, 03:25 PM
Hey all
I've gathered some code from several sources that allows me to do a zip-code radius lookup with a given radius and zip. For the most part, it works really well, but everyone so often, some test data I put in causes the lon range to be much to big. Here are the calculation for establishing a +/- value from a given radius (in other words, I'm really creating a box, not a circle)$lat_range = round($radius/69.172, 6);
$lon_range = round(abs($radius/(cos($lat) * 69.172)), 6);The $lat_range calculation is pretty straightfoward. I'm assuming the 69.172 is a rough constant for the number of miles per 1 latitude degree. It always seems to be accurate.
The $lon_range, however, somtimes get's messed up. I'm struggling to see what the original author was doing here...
Anyhow, any input is great. I'm gonna keep looking around, but most of my Google searches find me Zip Locator pages themselves, and not any code or methods behind the process.
Oh, ya, here's my test page (http://www.lanwizards.com/ziptest.php) and click this link (http://www.lanwizards.com/ziptest.php?radius=10&zip=75001&valid=true) for an example when the lon_range is way off.
I've gathered some code from several sources that allows me to do a zip-code radius lookup with a given radius and zip. For the most part, it works really well, but everyone so often, some test data I put in causes the lon range to be much to big. Here are the calculation for establishing a +/- value from a given radius (in other words, I'm really creating a box, not a circle)$lat_range = round($radius/69.172, 6);
$lon_range = round(abs($radius/(cos($lat) * 69.172)), 6);The $lat_range calculation is pretty straightfoward. I'm assuming the 69.172 is a rough constant for the number of miles per 1 latitude degree. It always seems to be accurate.
The $lon_range, however, somtimes get's messed up. I'm struggling to see what the original author was doing here...
Anyhow, any input is great. I'm gonna keep looking around, but most of my Google searches find me Zip Locator pages themselves, and not any code or methods behind the process.
Oh, ya, here's my test page (http://www.lanwizards.com/ziptest.php) and click this link (http://www.lanwizards.com/ziptest.php?radius=10&zip=75001&valid=true) for an example when the lon_range is way off.