# distance between zip codes

• Feb 5, 2002, 18:04
Technosailor
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? :D

Sketch
• Feb 5, 2002, 20:24
freakysid
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.

:)
• Feb 7, 2002, 02:34
DR_LaRRY_PEpPeR
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. :)
• Feb 7, 2002, 03:54
freakysid
Or you could just double your age and add the temperature and call it a calculated guess.

Well. hehe, err, um, ... :p
• Feb 8, 2002, 12:07
Technosailor
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
• Aug 10, 2002, 05:35
Andrew-J2000
speak to flawless_coder as he has something like that.
• Aug 18, 2002, 16:00
jkh1978
mysql statement?
I found a database of lat and long on a government database.

DR_LaRRY_PEpPeR, how do you do your MySQL statement?
• Aug 18, 2002, 20:19
johnyboy
Re: mysql statement?
Quote:

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 :)
• Aug 19, 2002, 18:54
-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
• Aug 19, 2002, 19:55
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...
• Aug 19, 2002, 20:12
Hierophant
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.
• Aug 20, 2002, 02:30
johnyboy
Quote:

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) {         \$l1 = deg2rad (\$l1);         \$sinl1 = sin (\$l1);         \$l2 = deg2rad (\$l2);         \$o1 = deg2rad (\$o1);         \$o2 = deg2rad (\$o2);                                         return (7926 - 26 * \$sinl1) * asin (min (1, 0.707106781186548 * sqrt ((1 - (sin (\$l2) * \$sinl1) - cos (\$l1) * cos (\$l2) * cos (\$o2 - \$o1))))); }```
• Aug 20, 2002, 14:50
-Oz-
coolness
• Aug 20, 2002, 19:31
alexbotkin
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
• Nov 20, 2004, 13:33
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 :)

• Nov 20, 2004, 13:48
beetle
• Nov 20, 2004, 18:27
jbr
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!