【问题标题】:ggmap geocode function returns same lat and lon coords many different addresses - batch geocodeggmap地理编码函数返回相同的经纬度坐标许多不同的地址 - 批量地理编码
【发布时间】:2019-12-16 09:49:06
【问题描述】:

我在数以万计的地址上使用 ggmap 中的地理编码功能,并遇到一个问题,即 google API 为我的所有地址返回相同的纬度和经度坐标,这些地址非常不同(不同的城市和不同的邮政编码)。

我基本上以这段代码为例: http://www.storybench.org/geocode-csv-addresses-r/

这是我的代码。我得到的示例输出位于代码底部的链接中。提前致谢,任何建议将不胜感激!

origAddress <- read.csv("C:/Projects/address_list2014.csv", stringsAsFactors = FALSE)

#combine street, city and state into one column separated by a comma
origAddress$addresses <- paste(origAddress$street, ",", origAddress$city, ",", origAddress$state)

geocoded <- data.frame(stringsAsFactors = FALSE)

for(i in 1:nrow(origAddress))
{
  # Print("Working...")
  result <- geocode(origAddress$addresses[i], output = "latlona", api = "google", 
                    key = "My_google_api_key")
  origAddress$lon[i] <- as.numeric(result[1])
  origAddress$lat[i] <- as.numeric(result[2])
  origAddress$geoAddress[i] <- as.character(result[3])
}

【问题讨论】:

  • 对不起,我试过了,但我无法重现您的问题。您确定上面粘贴的代码与您正在运行的代码完全相同,也许您有一个 1 而不是 i。也许您遇到了超时问题,并且变量没有在每个循环中刷新。尝试在循环中添加print(result) 以帮助诊断问题。

标签: r google-maps ggmap


【解决方案1】:

在玩了这个之后,我终于找到了问题。其中一些地址有一个符号:“#”用于单元或公寓编号,而 # 导致代码出现某种类型的问题。一旦我删除了所有 # 符号,代码就会运行干净。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-08-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-09-09
    • 2019-06-18
    • 2014-01-16
    • 2012-01-17
    相关资源
    最近更新 更多