Fog Creek Software
Discussion Board

displaying distance between 2 addresses

Well, this forum is getting a little crowded, but I'll pose this problem anyway...

I'm building a (inhouse) web-based database app that allows a client to compare one rental property with another.  I'd like to display the distance between the two properties (in miles).

I'm looking for an inexpensive solution for implementing this.  A web service (which I can integrate with my server-side Java app) would be great.  I suspect the more elaborate mapping tools offered by MapQuest, etc. are overkill.  Anyone played with something similar?

Friday, January 23, 2004

a quick comment on my original question...

It seems that inexpensive solutions are available to calculate distance between zip codes (based on freely available US census data).

But I'm looking for something that does this by street address if possible.

Friday, January 23, 2004

Are we talking "as the crow flies", or "as the car drives"?

Friday, January 23, 2004

As the car drives, look at Microsoft's MapPoint web service.  Don't know much about pricing, but seems like it'd do the trick. 

You could always write a parser for something like mapquest to extract the data you need.

Friday, January 23, 2004

Most of the GIS solutions are quite expensive, and while MapPoint ( offers a web service product, the pricing (last I checked) was of the "how much do you have?" sort.

Of course either way you need some sort of GIS lookup as you need to resolve string addresses to locations, and if you want the crow distance there are algorithms to convert longitude/latitude to distances, otherwise you'll have to use the route planning of the tools.

Dennis Forbes
Friday, January 23, 2004

Re: crow vs car.  Preferably direct distance, but driving distance would be reasonable. 

I thought about scraping from one of the consumer websites (mapquest etc) but I'm sure that's against their usage policies.

Friday, January 23, 2004

Dennis Forbes
Friday, January 23, 2004

What you really want is a solution that can be broken down into two parts:

1. Geocoding, or translating a legit address into Longs and Lats. Using ActiveX/Com and Mappoint 2004 North America you can resolve such addresses for all 50 states and territories, plus all of Canada. If you buy Mappoint 2004 Europe you should be able to do the same.

2. Distance calculation, there are two general formulas you'll find on the net, the lazy way, and the slightly more accurate way. The lazy way assumes that the Earth is a sphere, the accurate way assumes Earth is what it is, spherical blob of dirt but not quite a perfect sphere. Get one of these formulas and plug both A and B in and get your D.

MapPoint is great, but there are licensing implications that make prevent you from doing this. You'll have to check with your corporate lawyers and read all the fine points.

Direct subscription to MapPoint Web Services is far from cheap, the price range it is in is entirely inappropriate for "light lookups". I heard there are 3rd party intermediates that subscribes to Web Services and resell that service in smaller subscription models friendier towards to the weekend website designers.

Li-fan Chen
Friday, January 23, 2004

If you think about just how much look ups you have to do (depends on your application).. you may discover you'll do far fewer lookups than you think (to the point of it being feasible for you to walk around town with a GPS). On the other hand, some applications depend perfect lookups. So it really depends on what you are doing for your project. For your project it sounds like MapPoint 2004 North America would be just perfect.

Li-fan Chen
Friday, January 23, 2004

"I'm building a (inhouse) web-based database app that allows a client to compare one rental property with another.  I'd like to display the distance between the two properties (in miles)."

Hopefully, you've already thought of this and were just asking in general terms how to measure the distance between *any* two properties, but based on the text as written a reality-check seems appropriate.  Specifically, the client likely doesn't care about the distance between two rental properties since they're only going to live in one of them (unless they're so fabulously wealthy they can afford two homes or they're looking for two places so they can live apart from their estranged spouse).  What would be cool is if they could easily answer questions like, "How close is this property to my workplace/the closest school/shopping center/fire department/etc.?"

Friday, January 23, 2004

Thanks for the useful tips.

Actually, to explain a bit further, my client is a professional services firm that is building a database of properties for use in market studies.  A user of the tool would be a developer (the real estate kind) who would be comparing their property with the other properties in the database.  One of the criteria (besides the obvious ones of rent, bedrooms, etc) is how far the other properties are from the subject of the study.  So I really do need an on the fly point A to point B.

After thinking about this and talking to various folks, I think the way to go is to lookup and store the lat/longitude of the property in the database when it is entered and then calculate the distance when generating reports on demand.  Searching google for the term "geocode" was a big help.  I also found a formula to calculate distance based on lat/long (assuming a sphere).  I'll look harder for the more realistic algorithm. 

I've found several web services that look like they would work for the geocode lookup.  I prefer a web server to an installed tool for compatibility reasons (it's a server-side java web app) and because then I'm more likely to always have recent data.

If anybody's interested in the specifics of the solution I come up with (with comparison of vendors, etc) I'd be happy to share once I finish the research.  Drop me an email.

Saturday, January 24, 2004


I too need software which will do those two things, but for me crow-fly-route is better.  I need:

1. free, or uber-cheap, software or web service which will allow us to convert street address in to lat/long.

2. determine the crows-fly distance between two lat/long.  Or, even better, determine if a lat/long is located within a polygon defined by points of lat/long.

The second part is pretty easy using basic trig and geometry, but I can'd do it without part #1.  PLEASE help -- if anyone knows, please email me at

Also, we are developing our app in java on linux, so the app that does #1 would need to expose some interface that we could code against (either java or come native interface on linux).

Thanks SOOOOOO much!  We just can't afford the huge GIS software packages which do way more than our simple needs.

Lon F. Binder
Tuesday, February 3, 2004

Did you get an inexpensive solution to your distance between two addresses using the shortest driving distance.  There were a few good suggestions on your forum; but I did not see your final resolution.  I need something simular for distance between a home address and a work address.  Let me know what you did.  Thanks.

Will Anderson

William Anderson
Wednesday, July 14, 2004

*  Recent Topics

*  Fog Creek Home