Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
• Status: Solved
• Priority: Medium
• Security: Public
• Views: 1250

# How to calculate distance between two zip codes?

Do you have a routine that calculates the distance between two zip code?

If you don't have a routine, an algorithm that I can use to calculate the distance between zip codes.

On yahoo maps if you enter in the starting and ending zip codes it will display the distance in miles between the zip code.  This is an example of the functionality I am looking for.

Languages: asp, javascript,  vb - dll
0
swansonplace
• 5
• 3
• 2
• +2
5 Solutions

Commented:
this is not possible, unless you have a Google/Yahoo/etc. database
0

Commented:
There is not such "algorithm " without the data, which you don't have or have access to.
0

Commented:
Hello there,

To calculated distances between zipcodes, you will need to have a database with every zipcode in the US, plus Longitude and Latitude for each.

http://blog.devspan.com/2005/10/efficiently-calculating-zip-code.html
http://www.4guysfromrolla.com/webtech/010500-1.shtml
http://www.zipinfo.com/products/z5ll/z5ll.htm
0

Commented:
Hello,

I suggest that you
2 - use PHP/ASP/whatever to lookup the longitude & latitude of your ZIP code OR __Street Address__ via their API - Google has a nice How-to section, i can also help you further if you get stuck
3 - Use Great Circle Distance Formula:
IF YOUR TRIG functions are in degrees:
3963.0 * arccos[sin(lat1) *  sin(lat2) + cos(lat1) * cos(lat2) * cos(lon2 - lon1)]
3963.0 * arccos[sin(lat1/57.2958) * sin(lat2/57.2958) + cos(lat1/57.2958) * cos(lat2/57.2958) *  cos(lon2/57.2958 -lon1/57.2958)]
0

Commented:
@swansonplace

I would agree and go with @mkulon
0

Commented:
0

Commented:
I forgot to mention which gives a detailed explanation for calculating distance between postal codes...

http://authors.aspalliance.com/tmorford/distance/calculate_Zip_1.asp
0

Author Commented:
I really liked the google maps api but it is only available to wbsites that are generally accessible to consumers without charge.  My is an internal website that is used for business.

I am corrected. I do not need the radius, but the driving distance from two zip codes.  Do you know how I could get this.
0

Commented:
Do whatever you want until and unless you interact with some of the biggies like YAHOO/GOOGLE/ZIPCODES etc who have built such kind of data you won't be able to get through.

0

Author Commented:
Bugs,

I didn't understand the last statement:

Do whatever you want until and unless you interact with some of the biggies like YAHOO/GOOGLE/ZIPCODES etc who have built such kind of data you won't be able to get through.

Are you saying that the biggies servers are so bogged down, that I won't be able to get in.

swansonplace
0

Commented:
@swansonplace

Pardon my typing....

What i meant was the only way to get this kind of detail is by accessing the database of the biggies like YAHOO/GOOGLE or other providers using their API's which come both free as well as paid. Depending upon the nature of your website you can select the services offered and start working.

I guess thats what @golfdoctor and @mkulon, were spot on and specified at the begining of this thread.
0

Author Commented:
Just in case anyone else is looking for the same issue, I have found but not test the following open source code.  It doesn't do what we have been discussing on this thread, however, if you are looking for a low cost way to help your users get all zipcodes within a certain radius give this one a shot.