Google 映射 API 不正确的地理编码地址
Google maps API incorrectly geocoding address
我正在尝试查找地址列表的纬度和经度,例如,“108 CYPRESS RD GREENE , NY 13778”。但是,当我将其插入 Google 的 API(例如使用文本框 here)时,它会 returns 另一个地址:
"300 CYPRUS LN ENDICOTT NY 13760"
我能做些什么来帮助Google的API(或我也用过的RDSTK)正确识别经纬度吗?
我不确定该网站,但请尝试使用一些实际的 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")
我正在尝试查找地址列表的纬度和经度,例如,“108 CYPRESS RD GREENE , NY 13778”。但是,当我将其插入 Google 的 API(例如使用文本框 here)时,它会 returns 另一个地址: "300 CYPRUS LN ENDICOTT NY 13760"
我能做些什么来帮助Google的API(或我也用过的RDSTK)正确识别经纬度吗?
我不确定该网站,但请尝试使用一些实际的 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")