# Thread: Trig experts...help me with some lant/long stuff

1. ## Trig experts...help me with some lat/long stuff

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)
PHP Code:
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 and click this link for an example when the lon_range is way off.

2. i posted a function called haversine here:
http://www.sitepointforums.com/showt...458#post531535
not sure if that's going to be any use to you, but it might

3. 1) I'm already using haversine for distance
2) I've already fixed the problem anyway

Thanks just the same

4. Originally posted by beetle
2) I've already fixed the problem anyway
Well, how'd you fix it? What was wrong?

5. Instead of finding a +/- range for the coordinates, I stuffed the calculations right into the SQL statment....

Code:
\$sql = "SELECT \$this->zipCol
FROM \$this->zipTable
WHERE (
POW((69.172*(\$this->lonCol-\"\$this->lon\")*cos(\$this->lat/57.3)),2) +
POW((69.172*(\$this->latCol-\"\$this->lat\")),2)
I got these calculations from another website...works great!

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•