我发现需要使用 here.com 的 REST API 的五个选项(如下)的解决方案。我首先使用来自library(tigris) 的表fips_codes 交叉引用USGS 表中的FIPS 代码与县和州名称。这让我可以将名字放在地址行中,例如Boulder County, CO。接下来,我写了一个小函数here_now,示例用法为:
here_now("Boulder+County,+CO") # $lat: 40.08791; $lon: -105.3447
实现是使用来自library(jsonlite) 的fromJSON 调用REST API
here_now <- function(searchtext) {
AppCode <- getOption("hereAppCode")
AppID <- getOption("hereAppID")
rootURL <- "https://geocoder.api.here.com/6.2/geocode.json?"
app_id = paste("app_id", AppID, sep="=")
app_code = paste("app_code", AppCode, sep="=")
searchtext = paste("searchtext", searchtext, sep="=")
request <- paste(paste(rootURL, app_id, sep=''), app_code, searchtext, sep="&")
response = fromJSON(request)
res <- list()
res$lat <- response$Response$View$Result[[1]]$Location$NavigationPosition[[1]]$Latitude
res$lon <- response$Response$View$Result[[1]]$Location$NavigationPosition[[1]]$Longitude
res
}
此外,我使用了 FCC 的反向地理编码 API 来验证:https://geo.fcc.gov/api/census/
我尝试过的地理编码选项包括:
- 通过 ggmap 的谷歌 API(需要 API 密钥,需要信用卡)
- mapquest API(需要 API 密钥,不需要信用卡)
- 数据科学工具包的 RDSK 实施
- 通过同名的 R 包提供 Geonames 服务
- Here APIs(需要 AppID 和 AppCode,免费增值模式)