如何使用邮政编码和`ggmap`函数提取经度和纬度

我有一个邮政编码列表,我想找到它们相关的经度和纬度,以便将它们绘制在地图上。例如,我在下面展示了几个邮政编码:

code <- c("V6G 1X5","V6J 2A4","V5V 3N2")

现在,我想使用 ggmap 函数找到每个邮政编码的经度和纬度。我该怎么做?

rxwywy 回答:如何使用邮政编码和`ggmap`函数提取经度和纬度

ggmap::geocode()。请注意,您可能需要先注册 Google 地图 API 密钥。 见https://rdrr.io/cran/ggmap/man/register_google.html

library(ggmap)
library(tidyverse)
#register_google(key = "your_api_key_here") 

code <- c("V6G 1X5","V6J 2A4","V5V 3N2")

df_points <- ggmap::geocode(location = code)
map_vancouver <- get_googlemap(center = "Vancoucer,BC,Canada",zoom = 13)

ggmap(map_vancouver) +  geom_point(data = df_points,aes(x = lon,y = lat),colour = "red")

enter image description here

本文链接:https://www.f2er.com/560240.html

大家都在问