街道地址为地理纬度/经度 [英] street address to geolocation lat/long
问题描述
我正在考虑rChart / LeafLet为我县的房屋销售创建一个闪亮的应用程序。在任何时候都有几百间房屋可供出售。想要为所有人映射街道地址到地理位置(纬度/经度)并将其显示在地图上。因此,我正在寻找可以将街道地址映射到地理位置的r软件包,服务或数据库。
I am considering rChart/LeafLet to create a shiny app for housing sales in my county. There are several hundred houses for sale at any given time. Want to map street address-to-geolocation (lat/long) for all and display them on a map. So, I am looking for a r package, service or database that can map street address to geolocation.
推荐答案
这是一个基于哈维建议的功能。它会查找地址并给出第一个结果的坐标。查看函数中 x
的结构,以查看可以获得的其他信息。
Here is a function based on Harvey's suggestion. It will look for the address and give the coordinates of the first result. Have a look at the structure of x
in the function to see other information you can get.
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
}
For example:
R> geocodeAdddress("Time Square, New York City")
[1] -73.98722 40.7575
这篇关于街道地址为地理纬度/经度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!