reverseGeocode <- function(crd, result = 1, pause.time = 0.02) {
r <- result
url <- "http://maps.google.com/maps/api/geocode/json?latlng="
url <- paste0(url, crd[2], "+", crd[1], "&sensor=false")
doc <- URLencode(url)
x <- RJSONIO::fromJSON(doc, simplify = FALSE)
if (x$status == "OK") {
out <- list()
out$address <- x$results[[r]]$formatted_address
# Data.frame of address components for checking:
name <- do.call(rbind, lapply(x$results[[r]]$address_components, function(y)
c(y$long_name, y$short_name)))
type <- sapply(x$results[[r]]$address_components, function(y)
paste(y$types, collapse=", "))
out$address.components <- data.frame(cbind(name, type))
out$address.components[] <- lapply(out$address.components, as.character)
names(out$address.components) <- c("long_name", "short_name", "type")
return(out)
} else {
out <- list(address = NA, address.components = data.frame(long_name = NA,
short_name = NA,
type = NA))
warning("Request Status: ", x$status)
}
Sys.sleep(pause.time)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.