【发布时间】:2021-06-29 00:06:31
【问题描述】:
我有一个街道地址列表,我想将其地理编码到县。我在 R 中工作。下面是简化示例。不幸的是,由于新的 Google API 服务条款,您需要拥有自己的 API 密钥才能运行我的代码——它不应该被共享,所以请不要将它包含在您的解决方案代码中。
我怀疑这是格式问题,但我对 R 太陌生,不知道解决方案。
library(tidyverse)
library(ggmap)
register_google(key = <YOUR GOOGLE KEY>)
ltr <- letters %>% head(5)
adr <- c('110 State St, Albany, NY' ,
'100 State Cir, Annapolis, MD' ,
'206 Washington St SW, Atlanta, GA' ,
'210 State St, Augusta, ME' ,
'1100 Congress Ave, Austin, TX')
rawAdr <- data.frame(ltr , adr)
# the following only retrieves latitude and longitude
latlonAdr <- geocode(location = rawAdr$adr) %>%
bind_cols(rawAdr , .)
# the following retrieves county (among much other information),
# but it is formatted in a way that is
# impossible to use. For instance, county a is in variable long_name...17,
# but the same name is repeated for all addresses. The county for address b is given in
# long_name...64, again the same name for all addresses.
geoAdr <- geocode(location = rawAdr$adr , output = 'all') %>%
bind_cols(rawAdr , . )
我想要一个列出 ltr、adr 和(正确)县的文件。感谢您的任何帮助! (抱歉,我将有几个小时无法查看答案。)
【问题讨论】: