[R] computing distance in miles or km between 2 street addre

hadley wickham h.wickham at gmail.com
Fri Sep 7 02:23:47 CEST 2007


On 9/6/07, Ted Harding <Ted.Harding at manchester.ac.uk> wrote:
> On 06-Sep-07 18:42:32, Philip James Smith wrote:
> > Hi R-ers:
> >
> > I need to compute the distance between 2 street addresses in
> > either km or miles. I do not care if the distance is a "shortest
> > driving route" or if it is "as the crow flies."
> >
> > Does anybody know how to do this? Can it be done in R? I have
> > thousands of addresses, so I think that Mapquest is out of the
> > question!
> >
> > Please rely to: philipsmith at alumni.albany.edu
> >
> > Thank you!
> > Phil Smith
>
> That's a somewhat ill-posed question! You will for a start
> need a database of some kind, either of geographical locations
> (coordinates) of street addresses, or of the metric of the
> road network with capability to identify the street addresses
> in the database.

I think it's perfectly well-posed, but you'll need to use some
resources outside of R.

The term for converting street addresses to lat/long values is called
geocoding, and wikipedia has a good introduction:
http://en.wikipedia.org/wiki/Geocoding.  There are a couple of free
geocoding web services for US addresses: e.g.
http://developer.yahoo.com/maps/rest/V1/geocode.html or
http://geocoder.us/.  For non-US addresses you'll have to google
around (e.g. international geocoding), and depending on the country
and level of detail you require, you may have to pay.

Once you've got lat and longs, computing grand circle distance is
easy.  Computing driving distances is harder, but may be possible with
(e.g.) the google maps API -
http://www.google.com/apis/maps/documentation/index.html#Driving_Directions.
 Googling for driving directions api suggests some other
possibilities.

Hadley



More information about the R-help mailing list