[R] Retrieving latitude and longitude via Google Maps API

2 views
Skip to first unread message

Nutter, Benjamin

unread,
Mar 16, 2010, 3:42:18 PM3/16/10
to r-h...@r-project.org
Does anyone have any experience retrieving latitutde and longitude for
an address from the Google Maps API?

I'd like to have an R script that submits a street address, city, state,
and zip code and returns the coordinates. So far, I've been submitting
the coordinates from another program, then loading the coordinates in R
and merging them back into the data frame I want to use. It'd be nice
to be able to do it all in one script, but I'm not comprehending the API
thing very well.

I'm using R 2.9.1 on Windows XP. Any suggestions or pointers?

Benjamin



Benjamin Nutter | Biostatistician | Quantitative Health Sciences
Cleveland Clinic | 9500 Euclid Ave. | Cleveland, OH 44195 |
(216) 445-1365

===================================

P Please consider the environment before printing this e-mail

Cleveland Clinic is ranked one of the top hospitals
in America by U.S.News & World Report (2009).
Visit us online at http://www.clevelandclinic.org for
a complete listing of our services, staff and
locations.


Confidentiality Note: This message is intended for use\...{{dropped:13}}

______________________________________________
R-h...@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Phil Spector

unread,
Mar 16, 2010, 4:57:07 PM3/16/10
to Nutter, Benjamin, r-h...@r-project.org
Benjamin -
Perhaps this will get you started:

> addr = '1600 Pennsylvania Avenue, Washington, DC'
> url = paste('http://maps.google.com/maps/api/geocode/xml?address=',
+ addr,'&sensor=false',sep='')
> library(XML)
> doc = xmlTreeParse(url)
> root = xmlRoot(doc)
> lat = xmlValue(root[['result']][['geometry']][['location']][['lat']])
> long = xmlValue(root[['result']][['geometry']][['location']][['lng']])
> lat
[1] "38.8976500"
> long
[1] "-77.0356669"

- Phil Spector
Statistical Computing Facility
Department of Statistics
UC Berkeley
spe...@stat.berkeley.edu

Michael Denslow

unread,
Mar 16, 2010, 5:04:29 PM3/16/10
to Nutter, Benjamin, r-h...@r-project.org
Hi Benjamin,

>
> On Tue, 16 Mar 2010, Nutter, Benjamin wrote:
>
>> Does anyone have any experience retrieving latitutde and longitude for
>> an address from the Google Maps API?

This thread from r-sig-geo may be of interest:
https://stat.ethz.ch/pipermail/r-sig-geo/2010-March/thread.html#7788

Hope this helps,
Michael

--
Michael Denslow

I.W. Carpenter Jr. Herbarium [BOON]
Department of Biology
Appalachian State University
Boone, North Carolina U.S.A.
-- AND --
Communications Manager
Southeast Regional Network of Expertise and Collections
sernec.org

36.214177, -81.681480 +/- 3103 meters

hadley wickham

unread,
Mar 16, 2010, 6:10:18 PM3/16/10
to Michael Denslow, r-h...@r-project.org
>>> Does anyone have any experience retrieving latitutde and longitude for
>>> an address from the Google Maps API?
>
> This thread from r-sig-geo may be of interest:
> https://stat.ethz.ch/pipermail/r-sig-geo/2010-March/thread.html#7788

In particularly, note that what you are doing is against the google
terms of service.

To do it legally, with minimal cost, try https://webgis.usc.edu/.
It's free for <2500 addresses, $20 for 10,000, and $160 for 100,000.

Hadley

--
Assistant Professor / Dobelman Family Junior Chair
Department of Statistics / Rice University
http://had.co.nz/

Greg Snow

unread,
Mar 17, 2010, 1:07:25 PM3/17/10
to Nutter, Benjamin, r-h...@r-project.org
You may want to look at http://www.openstreetmap.org/ or http://maps.cloudmade.com/ instead of google maps. I don't know if they give the same detail/searches, but open source sites tend to be easier to work with and have fewer restrictions on use. While I like the google maps, I tend to not use them for anything other than personal browsing since I am not sure about the legal/copyright issues.

Hope this helps,

--
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg...@imail.org
801.408.8111

Reply all
Reply to author
Forward
0 new messages