简体   繁体   English

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

[英]how to get geocode in R?

i have tried 2 approaches to get the long lat of location.我尝试了 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)

or或者


A2_df <- mutate_geocode(A1, loc)

but both do not work但两者都不起作用

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

any ideas to get the respectively code without API key?有什么想法可以在没有 API 密钥的情况下获得相应的代码?

Is this what you are looking for?这是你想要的?

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

data数据

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

Created on 2021-03-30 by the reprex package (v1.0.0)代表 package (v1.0.0) 于 2021 年 3 月 30 日创建

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM