distance from one zip code to another zip code

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
psychotomus
Forum Contributor
Posts: 487
Joined: Fri Jul 11, 2003 1:59 am

distance from one zip code to another zip code

Post by psychotomus »

anyone know how to determine the distance between zip codes or if theres some functions floating around the net i can use freely to determine this (for usa residents)
User avatar
TheMoose
Forum Contributor
Posts: 351
Joined: Tue May 23, 2006 10:42 am

Post by TheMoose »

You'd need a listing of all the zipcodes and their relative latitude and longitudes in order to do a distance calculation. Yes, there are things that exist for the US, but I believe for most of them you have to pay.
psychotomus
Forum Contributor
Posts: 487
Joined: Fri Jul 11, 2003 1:59 am

Post by psychotomus »

Wouldn't happen to know of any links?
User avatar
TheMoose
Forum Contributor
Posts: 351
Joined: Tue May 23, 2006 10:42 am

Post by TheMoose »

psychotomus
Forum Contributor
Posts: 487
Joined: Fri Jul 11, 2003 1:59 am

Post by psychotomus »

thanks you sir.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

There have been several threads here dealing with the "great circle" math to calculate the distance, what's in the radius and so forth.
psychotomus
Forum Contributor
Posts: 487
Joined: Fri Jul 11, 2003 1:59 am

Post by psychotomus »

feyd wrote:There have been several threads here dealing with the "great circle" math to calculate the distance, what's in the radius and so forth.
and people don't think algebra and higher math is involved in programming =)
User avatar
veridicus
Forum Commoner
Posts: 86
Joined: Fri Feb 23, 2007 9:16 am

Post by veridicus »

The German company I've worked with gave us geodata in both latitude/longitude and x/y format. They run an algorithm that basically flattens the earth so very simple algebra can be run during searches for fast distance calculations.
User avatar
CoderGoblin
DevNet Resident
Posts: 1425
Joined: Tue Mar 16, 2004 10:03 am
Location: Aachen, Germany

Post by CoderGoblin »

Check out Geonames for other countries. You do need the great circle algorithm. I know I use postgres but the method I use to access information quickly is to calculate the distance from a known location (In Germany, Aachen where I work) and store that information in the database as X,Y points (North,East as km). I can then simply use the database geometry functions/Trig rather than relying on calculating Great Circle each time. It needs a bit of pre-processing to get the North/East distances but is fast.
MicahCarrick
Forum Newbie
Posts: 23
Joined: Sat Apr 09, 2005 5:40 pm

Post by MicahCarrick »

Here's my free script and database: PHP Zip Code Range and Distance Calculation
Post Reply