Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.