Created
June 18, 2012 14:05
-
-
Save drewconway/2948536 to your computer and use it in GitHub Desktop.
Grab lat / lon from an address using Google Maps
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Get a lat/lon value for each address | |
geocode.addr <- function(city, country) { | |
geo.url <- "http://maps.googleapis.com/maps/api/geocode/json?address=" | |
geo.text <- getURL(paste(geo.url, URLencode(paste(city, country, collapse="+")), "&sensor=false", sep="")) | |
geo.json <- fromJSON(geo.text) | |
if(geo.json$status == "OK"){ | |
return(geo.json$results[[1]]$geometry$location) | |
} | |
else{ | |
if(geo.json$status == "OVER_QUERY_LIMIT") { | |
stop("Hit rate limit") | |
} | |
else { | |
return(c(NA, NA)) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment