我试图用here.com对8K哥伦比亚地址进行地理编码,也就是获得经度。下面我分享一个简单地址的例子,请有人告诉我还缺少了什么,以及如何更好地构建我的完整地址以得到正确的lon对?
使用了以下代码:
dist.pairs <- readxl::read_excel("INFORME CONTRATO.XLSX",
sheet = NULL)
dist.pairs$id <- 1:nrow(dist.pairs)
set_key(api_key = "KEY")
names(dist.pairs)
# "label": "5 Rue Daunou, 75002 Paris, France",
# "countryCode": "FRA",
# "countryName": "France",
# "stateCode": "IDF",
# "state": "Île-de-France",
# "county": "Paris",
# "city": "Paris",
# "district": "2e Arrondissement",
# "street": "Rue Daunou",
# "postalCode": "75002",
# "houseNumber": "5"
dist.pairs$country <- "Colombia"
dist.pairs <- dist.pairs %>%
unite(fulladdress, Dirección, Ciudad, Departamento, country,
sep = ", ",
remove = F,
na.rm = T)
dist.pairs$geo.id <- 1:nrow(dist.pairs)
split.timer <- Sys.time()
dist.pairs.geocode <- geocode(address = dist.pairs$fulladdress) %>%
mutate(Check.geo.id = dist.pairs$geo.id[id]) %>%
mutate(Lat = st_coordinates(.)[,2],
Lon = st_coordinates(.)[,1],
Found = TRUE) %>%
select(Check.geo.id, Found, everything()) %>%
st_drop_geometry(.)
names(dist.pairs.geocode) <- ifelse(
substr(names(dist.pairs.geocode),1,5)=="Check",
names(dist.pairs.geocode),
paste0("Geocode_",names(dist.pairs.geocode))
)
dist.pairs <- dist.pairs %>%
left_join(x = .,
y = dist.pairs.geocode,
by = c("geo.id" = "Check.geo.id")) %>%
mutate(Geocode_Found = ifelse(!is.na(Geocode_Found), T, F)) %>%
select(-Geocode_id)
print(paste0("Time taken to geocode: ",round(Sys.time()-split.timer,2)))
发布于 2022-08-31 05:41:27
geocode API提供了制定限定查询的选项。当在单独的字段中捕获地址文本时,/geocode端点的限定地址输入是一个选项。例如,作为注册过程的一部分,或者无论何时结构化输入都是必需的。
例如,地址"425 W Randolph St,Chicago,IL 60606,United States“可以限定为以下一组子参数:
houseNumber=425 street=W Randolph St city=Chicago state=IL postalCode=60606 country=United State注意,在这种情况下,国家是一个地址的限定字段,它支持单个国家名称或大写国家代码。若要限制大写ISO 3166-1 alpha-3国家代码列表的结果,请使用in参数。
查询可以用以下方式表示:
获取https://geocode.search.hereapi.com/v1/地理代码?qq= houseNumber=425;street=W+Randolph+St;city=Chicago;state=IL;postalCode=60606;country=United+States &apiKey={YOUR_API_KEY}
如需详细资料,请参阅下列文件。指南/主题-api/code-geocode-Qualfied.html
https://stackoverflow.com/questions/73449470
复制相似问题