# Thread: distance between zip codes

1. ## distance between zip codes

Any ideas how I would try to measure the mileage between two zip codes (6 state area)? Anybody got any scripts for this or know wher3e to find one? Or do I need to get distances manually by doing Yahoo Map searches?

Sketch

2. Sketch, if you do an advanced search, I know that someone actually posted either the code for this or the algorithm some time ago. Could be exactly what you are looking for.

3. there's no way to calculate the distance between ZIP codes that i know of Sketch. what freakysid is talking about is code to calculate the distance between 2 points of latitude and longitude. i just finished an application that does this. i do the calculation in my MySQL query. this is plenty accurate for distances less than, say, 500 miles. you can get more accurate using the sine and arc cosine functions. here's the formula (from my query):

Code:
`SQRT(POW(lat1 - lat2, 2) + POW((lon1 - lon2) * COS(RADIANS((lat1 + lat2) / 2)), 2))`
then you can just multiply that value by the miles in a degree of latitude, which is about 70.

4. Or you could just double your age and add the temperature and call it a calculated guess.

Well. hehe, err, um, ...

5. I like that method best, freaky!

Anybody got any recommendations on buying a db of zips with lat and long in the db? I surely don't want to have to create it....

Sketch

6. speak to flawless_coder as he has something like that.

7. ## mysql statement?

I found a database of lat and long on a government database.

DR_LaRRY_PEpPeR, how do you do your MySQL statement?

8. ## Re: mysql statement?

Originally posted by jkh1978
I found a database of lat and long on a government database.
i could use something like that. would you post the url please jkh? i'd appreciate it if you would

9. thats pretty advanced, but make sure that the distance isn't too long, you should really use the curves to make the distance because you are going through earth currently with that algorithm. You have to make sure that you stay on the surface and that also depends what direction you are going. I don't know the algorithm i just know that it is neccessary for an accurate distance measurement.

--a high school senior

10. The telephone LD industry uses a database of this type of information for calculating rates of calls(internally). On a project I'm working with one of the item's we'll be having to purchase is this list of lats & lons for rerating LD bills.

I don't remember who has the list exactly, but I'm thinking it's Bell something...

11. There is no such thing as a distance between zip codes. They are based on Population Density. For XXX Amount of population you get a new zip code. I believe it is 50,000 people. This doesn't account for Zip Codes assigned to pre-sorted mail and post office boxes either.

For calculating mileage on a map and accounting for the curvature of the earth, Larry's calculation looks spot on. I did this almost two years ago in an Oracle application. I can't find the code right now however.

If you go to the U.S. Census Bureau's website, you can order TIGER data that allows you plot every address in the United States. It isn't the best mapping data but costs a lot less than what you would get from MapInfo or Telcontar which would run you in the 10,000s of thousands of dollars.

I have Telcontar's map data for California and Nevada here at home and that cost \$1500.00. It is also 1999 data so it is probably out of date by now.

12. Originally posted by -Oz-
thats pretty advanced, but make sure that the distance isn't too long, you should really use the curves to make the distance because you are going through earth currently with that algorithm. You have to make sure that you stay on the surface and that also depends what direction you are going. I don't know the algorithm i just know that it is neccessary for an accurate distance measurement.

--a high school senior
the curved way from here -
http://www.phpbuilder.com/snippet/de...=snippet&id=61

code from there -
Code:
```# Where:
#  \$l1 ==> latitude1
#  \$o1 ==> longitude1
#  \$l2 ==> latitude2
#  \$o2 ==> longitude2

function haversine (\$l1, \$o1, \$l2, \$o2)
{
\$sinl1 = sin (\$l1);

return (7926 - 26 * \$sinl1) * asin (min (1, 0.707106781186548 * sqrt ((1 - (sin (\$l2) * \$sinl1) - cos (\$l1) * cos (\$l2) * cos (\$o2 - \$o1)))));
}```

13. coolness

14. I believe that there are centroid lat lon locations for zip codes. It would only be an approximation. You need to check on data from GIS (geographic information systems) suppliers, I think.

Alex

15. ## GIS zip code data...

For GIS zipcode data, I would recommend to places:

1. www.nationalatlas.gov

2. www.geographynetwork.com.

At each place, you can download geographic data that may include centroids for zip code polygons. Incidentally, a zipcode is not really an "area" but a network of street segments. These segments are grouped together for the convenience of delivering the mail.

May want to go to usps.gov (the US Post Office) also.

Cheers!

Andy

16. Hi

I will share my code with you.... (offer only to the original poster)

PM me if you want the best code possible! The method I use gives the best results, I designed it using earth models and NASA geo thermo plates! I will also give you any (1) database from any (1) country in the world. Each database has every city/place and postal code!

Example....

http://zip.ya-right.com/distance/us/zip.php

C, ya...

J!

#### Posting Permissions

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