I've tried running the code to geocode locations in R via Google Maps and the XML
package from this blog post:
http://www.r-chart.com/2010/07/maps-geocoding-and-r-user-conference.html
Here are his functions:
getDocNodeVal=function(doc, path){
sapply(getNodeSet(doc, path), function(el) xmlValue(el))
}
gGeoCode=function(str){
library(XML)
u=paste('http://maps.google.com/maps/api/geocode/xml?sensor=false&address=',str)
doc = xmlTreeParse(u, useInternal=TRUE)
str=gsub(' ','%20',str)
lng=getDocNodeVal(doc, "/GeocodeResponse/result/geometry/location/lat")
lat=getDocNodeVal(doc, "/GeocodeResponse/result/geometry/location/lng")
c(lat,lng)
}
When I run gGeoCode()
, I get the following error:
> gGeoCode("Philadelphia, PA")
failed to load external entity "http%3A//maps.google.com/maps/api/geocode/xml%3Fsensor=false&address=%20Philadelphia,%20PA"
Error: 1: failed to load external entity "http%3A//maps.google.com/maps/api/geocode/xml%3Fsensor=false&address=%20Philadelphia,%20PA"
If I just paste into a browser the API url with Philadelphia, PA
appended to the end, like the string passed to xmlParseTree
, I get a result that looks like legitimate xml when I download it.
Is this an issue with the code, or have I failed to configure something or another?