Link to home
Start Free TrialLog in
Avatar of Zach Mann
Zach Mann

asked on

Best way to find the distance between two ZIP codes in C#

For part of a program I am creating I need to find the distance in miles between two ZIP codes.  This does not have to be exact, "as the crow flies" is fine.  I have found some solutions online but can not get them to work.  My background is in SQL but I have an understanding of programming logic, but I still can't get these to work in Microsoft Visual Studio.

The first one I found looked like it would do exactly what I wanted to do but the urls are not update and I am not sure where they may have moved to or what they used to be:
http://blog.codebrain.co.uk/post/2009/05/08/C-Distance-Between-Two-Postcodes.aspx

"http://maps.google.com/maps/geo?q={0}&output=xml" is no longer a valid link.

Another solution that I tried is:
https://www.techrepublic.com/blog/software-engineer/how-do-i-determine-the-distance-between-zip-codes-using-c/

For this one, the basic idea makes sense to me but I am not sure how to put it all in to action.  The link to download the examples is no longer valid and I am not sure where all of the code goes.  For instance, where do I need to reference "LoadData" from and what needs to be passed to it as the "path."  Also is the xml document stored in project somewhere?

Any insight into either of these solutions or even another that would work better are appreciated.  Thanks
Avatar of Bill Prew
Bill Prew

What type of volume are you looking at doing?  There are some web service APIs that are free for modest daily volumes, you might try one of those.  That assumes the machine running your code would have internet access?

Google also has an API for distance between points, link below, and a VB example of it's usage.

Lastly you could download an actual data file of ZIP Codes to lat and long coordinates, and then do the algorithm to calculate distance between those two coordinates.  A link for that below.

Hope these help.

Google

Other web service APIs

Local downloaded data


»bp
This question needs an answer!
Become an EE member today
7 DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.