ilovebigmacs
ilovebigmacs

Reputation: 993

How to calculate the distance between two locations with ASP.NET?

I'm wondering about the feasability of this below. Of course, I'm not asking for the complete code (although it would be nice!) but rather a way to achieve the following in ASP.NET:

I have a site. People register on it and provide their Country of residence as well as the ZIP code and City name which is then stored in a SQL Server DB. I have a search engine on my site and I would like one of the filtering options to be "only show me members living at a maximum distance of 100 kilometers".

Any ideas, hints, already written code I can re-use, free API's doing just that, etc... ?

Thank you for your time!

Upvotes: 0

Views: 8446

Answers (1)

David
David

Reputation: 73604

First, you need a way to look up the geocode (latitude and longitude) from the zip code. There are several web services for this, and also CSV files that you can download containing this data. Google, for example, provides geolocaiton servivces. I believe their API will also tell you the distance between two points.

At any rate, once you know the geocode, it's a simple matter of determining the distance using math. Sample code here:

(actually, my first Google search came up with a complete solution.)

Upvotes: 3

Related Questions