street address to geolocation lat/long

回眸只為那壹抹淺笑 提交于 2019-12-20 08:52:19

问题


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.


回答1:


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



回答2:


I have used Google Geolocation, This is simple to set-up and easy to implement on almost any project:

https://developers.google.com/maps/documentation/geocoding/intro



来源:https://stackoverflow.com/questions/32504880/street-address-to-geolocation-lat-long

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!