如何在 R 中获取地理编码?

how to get geocode in R?

我已经尝试了 2 种方法来获取位置的长纬度。

install.packages("maptools")
library(maptools)
A1 <- data.frame(A1= c("Dordrecht", "Berlin", "New York", 
                                    "Batu Pahat", "Edinburgh"), 
                                    stringsAsFactors = FALSE)

result <- lapply(A1[, 1], geocode_OSM)


A2_df <- mutate_geocode(A1, loc)

但两者都不行

        loc
  1    Dordrecht
  2    Berlin
  3    New York
  4    Batu Pahat 
  5    Edinburgh  

有什么想法可以在没有 API 密钥的情况下获得相应的代码吗?

这是您要找的吗?

library(tmaptools)

geocode_OSM(A1$A1)

#>        query       lat        lon   lat_min   lat_max    lon_min    lon_max
#> 1  Dordrecht 51.795881   4.677935 51.714123 51.823358   4.620404   4.884643
#> 2     Berlin 52.517037  13.388860 52.357036 52.677036  13.228860  13.548860
#> 3   New York 40.712728 -74.006015 40.477399 40.916179 -74.259090 -73.700181
#> 4 Batu Pahat  1.933333 103.000000  1.616728  2.200501 102.774169 103.256164
#> 5  Edinburgh 55.953346  -3.188375 55.818792 56.004084  -3.449533  -3.074951

数据

A1 <- data.frame(A1= c("Dordrecht", "Berlin", "New York", 
                       "Batu Pahat", "Edinburgh"), 
                 stringsAsFactors = FALSE)

reprex package (v1.0.0)

于 2021-03-30 创建