I am trying to reverse geocode a large data-set (around 100k). I used the revgeocode
function from the package ggmap
. I got the result for 1 entry
48 Grand View Terrace, San Francisco,
CA 94114, USA
48 Grand View Terrace Eureka Valley San Francisco
San Francisco County California United States
postal_code postal_code_suffix
, but I need to automate the process and use it for the entire data-set.
I tried
r <- lapply(revgeocode(location = (c(z$lon),c(z$lat)),
output = "more",
messaging = FALSE, sensor = FALSE, override_limit = FALSE,
client = "", signature = ""))
and got the errors for unexpected ',' in each step.
I tried to write the following loop too
r <- for(i in 1:10){
revgeocode(location = ("z$lon", "z$lat"),output = "more", messaging = FALSE, sensor = FALSE, override_limit = FALSE,client = "", signature = "")}
and got similar errors
Please provide some material or helpful links that will help me to write the loop for reverse geocoding. How to verify the authenticity of the data?
Based on this answer, you could create new variables in your data.frame
We use
mapply()
to process your coordinates and return the results in a listres
.Then, we use
rbindlist()
fromdata.table
to convert the list into adata.frame
(withfill = TRUE
since not all elements ofres
have the same lenghts i.e. some results do not return astreet_number
and apostal_code
) andcbind()
it to the original dataUpdate
Following up on your comment, if you want to process more than 2500 queries, you could subscribe to Google Maps APIs Premium Plan to unlock higher quotas. Then you can pass on your credentials to
revgeocode()
using thesignature
andclient
parameter.As per mentionned in the documentation:
You can see how it works under the hood by examining the
revgeocode()
source and see how the URL is constructed:Data
I have had a similar problem for integrating the API key. Basically it is a matter of integrating the API key in the URL that R calls. If this doesn't help you, you need to change the core code (look it up on Github) to allow for an argument calling a key.