PDA

View Full Version : Trig experts...help me with some lant/long stuff


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.

Socraties
10-31-2002, 06:55 PM
Ok I am a little confused the following 2 lines of code:

$lat_range = round($radius/69.172, 6);
$lon_range = round(abs($radius/(cos($lat) * 69.172)), 6);

Are not found in the link you provided with the code. All references i found to the value you have as $lat ... doesn't show it as a variable. Rather it shows it as just lat ... am i just looking at the wrong thing?

beetle
10-31-2002, 07:26 PM
Sorry, I've changed it up...I'm not needing the help anymore...I should have come back and said so...

Thanks just the same :D