Jump to content

Zip Codes Within A Radius


The Little Guy

Recommended Posts

I have this to calculate the distance it is from once zipcode to another:

SET @lat1 = '-093.076163';
SET @long1 = '+44.661216';
SELECT 96.1 * (180/pi()) *
    acos(
        sin(radians(@lat1)) * sin(radians(lat)) +
        cos(radians(@lat1)) * cos(radians(lat)) *
        cos(radians(log - @long1))
    )
as dist, zip, city from zipcodes having dist <= 15 order by dist limit 10000;

 

above code found here:

http://www.zipcodeworld.com/docs/distance.pdf

 

Currently it only seems to calculate the distance of a zipcode in the distance it is east / west of the current zipcode

 

For example I am using my current town (Rosemount, MN) and it says the closest town to me is St. Paul, MN. But if you look at Google it is about 15 miles (by air). Now if I go west and draw a line straight down from St. Paul, then it takes about what the above code calculates.

 

any suggestions to calculate longitude as well, or any other suggestions?

Link to comment
https://forums.phpfreaks.com/topic/229086-zip-codes-within-a-radius/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.