我在使用 googleway 包中的 google_geocode 函数批量地理编码时遇到问题。我想输入一个地址数据框,并为每个地址返回纬度和经度坐标。地址的数量远远超出了谷歌每天 2500 个查询的限制,因此该解决方案需要使用 API 密钥来允许购买更多查询。
## 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