【问题标题】:How to extract longitude and latitude using postal code and `ggmap` function如何使用邮政编码和`ggmap`函数提取经度和纬度
【发布时间】:2021-04-19 00:32:16
【问题描述】:

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

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

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

【问题讨论】:

标签: r ggplot2 ggmap postal-code


【解决方案1】:

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")

【讨论】:

  • 呵呵,我不知道ggmap 是否通过加拿大邮政编码进行反向地理编码。好的。我的链接答案会让您稍微不太方便地进行反向地理编码,但您可以在本地以您想要的任何数量进行此操作,而无需访问 Google 服务。
  • @BenBolker 非常感谢。您提供的链接实际上对我有用,使用那里提出的解决方案非常简单
  • @Nicolás Velásquez 非常感谢您的解决方案。这太棒了,我可以使用 ggmap 找到我所有点的位置。谢谢
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2019-03-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-01-01
相关资源
最近更新 更多