我正在考虑使用rChart/LeafLet为我的县创建一个晶亮应用程序,与住房销售相关。每次都有几百所房屋出售。希望将所有的街道地址映射到地理位置(纬度/经度),并在地图上显示它们。因此,我正在寻找一个能够将街道地址映射到地理位置的r软件包、服务或数据库。
我正在考虑使用rChart/LeafLet为我的县创建一个晶亮应用程序,与住房销售相关。每次都有几百所房屋出售。希望将所有的街道地址映射到地理位置(纬度/经度),并在地图上显示它们。因此,我正在寻找一个能够将街道地址映射到地理位置的r软件包、服务或数据库。
这是一个基于哈维建议的函数。它将查找地址并给出第一个结果的坐标。查看函数中x
的结构,以了解其他可以获取的信息。
geocodeAdddress <- function(address) {
require(RJSONIO)
url <- "http://maps.google.com/maps/api/geocode/json?address="
url <- URLencode(paste(url, address, "&sensor=false", sep = ""))
x <- fromJSON(url, simplify = FALSE)
if (x$status == "OK") {
out <- c(x$results[[1]]$geometry$location$lng,
x$results[[1]]$geometry$location$lat)
} else {
out <- NA
}
Sys.sleep(0.2) # API only allows 5 requests per second
out
}
例如:
R> geocodeAdddress("Time Square, New York City")
[1] -73.98722 40.7575
针对API要求进行修改的答案:
api_key <- c("YOUR_API_KEY")
geocodeAdddress <- function(address) {
require(RJSONIO)
url <- "https://maps.googleapis.com/maps/api/geocode/json?address="
url <- URLencode(paste(url, address, sep = ""))
url <- URLencode(paste(url, "&key=", api_key, sep = ""))
x <- fromJSON(url, simplify = FALSE)
print(x$status)
if (x$status == "OK") {
out <- c(x$results[[1]]$geometry$location$lng,
x$results[[1]]$geometry$location$lat)
} else {
out <- NA
}
Sys.sleep(0.2) # API only allows 5 requests per second
out
}
nominatim
: https://github.com/hrbrmstr/nominatim;ggmap::geocode
;geocodeHERE::geocodeHERE_simple
;geonames
包; 还有google r 街道地址地理定位
注:以上内容为需要翻译的内容,下同。 - hrbrmstr