SitePoint Sponsor |
|
User Tag List
Results 1 to 17 of 17
Thread: distance between zip codes
-
Feb 5, 2002, 18:04 #1
- Join Date
- Jun 2001
- Location
- Before These Crowded Streets
- Posts
- 9,446
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
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
-
Feb 5, 2002, 20:24 #2
- Join Date
- Jun 2000
- Location
- Sydney, Australia
- Posts
- 3,798
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
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 #3
- Join Date
- Jul 2001
- Location
- Missouri
- Posts
- 3,428
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
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))
- Matt** Ignore old signature for now... **
Dr.BB - Highly optimized to be 2-3x faster than the "Big 3."
"Do not enclose numeric values in quotes -- that is very non-standard and will only work on MySQL." - MattR
-
Feb 7, 2002, 03:54 #4
- Join Date
- Jun 2000
- Location
- Sydney, Australia
- Posts
- 3,798
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Or you could just double your age and add the temperature and call it a calculated guess.
Well. hehe, err, um, ...
-
Feb 8, 2002, 12:07 #5
- Join Date
- Jun 2001
- Location
- Before These Crowded Streets
- Posts
- 9,446
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
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 #6
- Join Date
- Aug 2001
- Location
- London
- Posts
- 2,475
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
speak to flawless_coder as he has something like that.
-
Aug 18, 2002, 16:00 #7
- Join Date
- May 2001
- Location
- Northern Virginia
- Posts
- 445
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
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 #8
- Join Date
- Apr 2002
- Posts
- 2,322
- Mentioned
- 3 Post(s)
- Tagged
- 0 Thread(s)
Re: mysql statement?
Originally posted by jkh1978
I found a database of lat and long on a government database.
-
Aug 19, 2002, 18:54 #9
- Join Date
- Nov 2001
- Location
- Phoenix, AZ, USA
- Posts
- 406
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
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 seniorOz
GamersMark - On Target Gaming
OzTheory - Programming and Web Solutions
AmIBlocked - Check if you've been blocked on IM
-
Aug 19, 2002, 19:55 #10
- Join Date
- Aug 2001
- Location
- North Carolina
- Posts
- 153
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
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 #11
- Join Date
- Aug 1999
- Location
- Lancaster, Ca. USA
- Posts
- 12,305
- Mentioned
- 1 Post(s)
- Tagged
- 0 Thread(s)
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 #12
- Join Date
- Apr 2002
- Posts
- 2,322
- Mentioned
- 3 Post(s)
- Tagged
- 0 Thread(s)
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
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 #13
- Join Date
- Nov 2001
- Location
- Phoenix, AZ, USA
- Posts
- 406
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
coolness
Oz
GamersMark - On Target Gaming
OzTheory - Programming and Web Solutions
AmIBlocked - Check if you've been blocked on IM
-
Aug 20, 2002, 19:31 #14
- Join Date
- May 2002
- Location
- Pittsburgh PA
- Posts
- 44
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
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 #15
- Join Date
- Nov 2004
- Location
- Atlanta, Georgia
- Posts
- 26
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
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
P.S. You can download free GIS software (called ArcExplorer) from www.esri.com. This will help you handle spatial data that you download and convert it to other formats for use in your application.
-
Nov 20, 2004, 13:48 #16
-
Nov 20, 2004, 18:27 #17
- Join Date
- Nov 2004
- Location
- Boston
- Posts
- 25
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
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!
Bookmarks