【问题标题】:Google maps API incorrectly geocoding address谷歌地图 API 错误地对地址进行地理编码
【发布时间】:2015-08-01 19:32:59
【问题描述】:

我正在尝试查找地址列表的纬度和经度,例如“108 CYPRESS RD GREENE, NY 13778”。但是,当我将其插入 Google 的 API(例如使用文本框 here)时,它会返回另一个地址: "300 CYPRUS LN ENDICOTT NY 13760"

我能做些什么来帮助 Google 的 API(或我也使用过的 RDSTK)正确识别纬度和经度吗?

【问题讨论】:

  • 我不确定链接页面中的结果来自哪里,但真正的 google-gecoding-API 会返回预期的结果:maps.googleapis.com/maps/api/geocode/…
  • ggmap::geocode("300 CYPRUS LN ENDICOTT NY 13760") 工作正常
  • nominatim::osm_search("300 CYPRUS LN ENDICOTT NY 13760", email="your@email.com") 似乎也可以工作(pkg at github.com/hrbrmstr/nominatim

标签: r google-maps geocoding google-geocoder


【解决方案1】:

我不确定那个网站,但请尝试使用一些实际的 R 代码。我在这个页面找到了一些即插即用的代码:http://www.r-bloggers.com/using-google-maps-api-and-r/

library(RCurl)
library(RJSONIO)
library(plyr)

url <- function(address, return.call = "json", sensor = "false") {
 root <- "http://maps.google.com/maps/api/geocode/"
 u <- paste(root, return.call, "?address=", address, "&sensor=", sensor, sep = "")
 return(URLencode(u))
}

geoCode <- function(address,verbose=FALSE) {
 if(verbose) cat(address,"\n")
 u <- url(address)
 doc <- getURL(u)
 x <- fromJSON(doc,simplify = FALSE)
 if(x$status=="OK") {
 lat <- x$results[[1]]$geometry$location$lat
 lng <- x$results[[1]]$geometry$location$lng
 location_type <- x$results[[1]]$geometry$location_type
 formatted_address <- x$results[[1]]$formatted_address
 return(c(lat, lng, location_type, formatted_address))
 } else {
 return(c(NA,NA,NA, NA))
 }
}

address <- geoCode("108 CYPRESS RD GREENE , NY 13778")
address

## [1] "42.3106291"                             
## [2] "-75.7923396"                            
## [3] "RANGE_INTERPOLATED"                     
## [4] "108 Cypress Road, Greene, NY 13778, USA"

看看它是什么样子的:

library(ggmap)
df <- data.frame(lat = as.numeric(address[1]), lon = as.numeric(address[2]))
map <- get_map("108 CYPRESS RD GREENE , NY 13778", zoom = 18)
ggmap(map) + geom_point(aes(x=lon, y=lat), data=df,colour="red", size=6) +
             ggtitle("108 CYPRESS RD GREENE , NY 13778")

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-04-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-28
    • 1970-01-01
    • 2019-06-10
    • 2014-12-17
    相关资源
    最近更新 更多