I'm having trouble using the google_geocode function in the googleway package to batch geocode. I'd like to input a data frame of addresses and have the latitude and longitude coordinates returned for each. The number of addresses is far beyond Google's 2,500 daily query limit, so the solution needs to use an API key to allow the purchase of more queries.
## Your Google API key
key<-"<insert key here>"
### Make Data Frame with two observations
Dt<-as.data.frame(matrix(c(" 4605 Langdon ST , Fernley , NV , 89408", -119.2026,
" 350 Quivera LN , Sparks , NV , 89441", NA), ncol=2))
###Change Column Names
colnames(Dt)<-c("address", "longitude")
### Make address column character
Dt$address<-as.character(Dt$address)
### Make data frame with one observation
dt<-Dt[1,]
### geocode one observation with googleway This Works!!
google_geocode(address = dt[,"address"],
key = key)
### batch geocode
res <- apply(Dt, 1, function(Dt){
google_geocode(address=list(Dt[,"address"]),
key = key)
})
## Error in Dt[, "address"] : incorrect number of dimensions
See Question&Answers more detail:os