【发布时间】:2016-05-15 22:23:51
【问题描述】:
我正在尝试使用 google api 密钥对数据集进行反向地理编码。我设法运行代码并获得了 10 个小样本的所需结果,但它给出了错误
Error in rgc$results[[1]] : subscript out of bounds
我设法通过使用以下代码集成了 api 密钥:
` revgx <- mapply(function(latlng, api_key){
url= paste("https://maps.googleapis.com/maps/api/geocode/json?","latlng=",latlng,"&key=",sep="")
rgc <- fromJSON(paste(readLines(url), collapse = ''))
rgc <- rgc$results[[1]]
with(rgc,{rgcdf <<- data.frame(
address = formatted_address
)})
for(k in seq_along(rgc$address_components)){
rgcdf <- cbind(rgcdf, rgc$address_components[[k]]$long_name)
}
names(rgcdf) <- c('address', sapply(rgc$address_components, function(l) l$types[1]))
# return 'more' output
rgcdf
},
y1$latlng)`
我也尝试使用相同的方法来合并 xml,但无济于事。请建议是否需要对代码进行任何更改。
【问题讨论】:
标签: r google-maps reverse-geocoding