tags:

views:

27

answers:

3

What is the best way to calculate AND add a field to a data file that shows the crow-fly distance (in miles) between two zip codes for each record (250K+) in a file? THANKS

A: 

Get a Google Earth API Key and use the API to calculate distances between two zip codes in your language of choice.

UPDATE:

If a web service isn't for you, you can check my OLD Visual Basic Posting on planet source code. It has a database of zip codes, their lat/long positions, and some VB code to calculate the distances between two zip codes. The Zipcode DB will probably require some updating, and it's in a MS Access format (but you can move that data anywhere).

Dutchie432
There are 250,000 records in the data file. I do not see where using what appears to be a manual web-site embedded service would be possible for this many iterations. Am I missing something? Hmmm.
Steve Henderson
Well, if you're only doing it once, that would still be a viable solution. If not, see my addition above.
Dutchie432
A: 

Hi,

You could use the Yahoo Geocoding Service to first get the latitude and longitude corrodinates for each zip code, then simply use the haversine formula to get the distance between any two sets of latitude/longitude data.

Here is a c# implementation of the haversine formula.

Enjoy!

Doug
+1  A: 

Use this page for the raw distance information. Then use this website for the formula from Adam Bellaire's response to calculate the distance.

There is no reason to use an external service as zip codes really don't change all that often.

Enjoy!

Evan Moran