首页 > 解决方案 > 无法通过 get_map() 函数下载地图

问题描述

我需要 get_map 函数的帮助,每次我使用它时,我都无法下载地图

例子:

get_map('Egypt',zoom = 'auto')

download.file(url, destfile = tmp, quiet = !messaging, mode = "wb") 中的错误:无法打开 URL ' http://maps.googleapis.com/maps/api/staticmap?center=Egypt&zoom=10&size= 640x640&scale=2&maptype=terrain&language=en-EN&sensor=false ' 另外:警告消息:在 download.file(url, destfile = tmp, quiet = !messaging, mode = "wb") 中:无法打开 URL ' http://maps .googleapis.com/maps/api/staticmap?center=Egypt&zoom=10&size=640x640&scale=2&maptype=terrain&language=en-EN&sensor=false ':HTTP 状态为 '403 Forbidden'

标签: rgoogle-mapsggmap

解决方案


ggmap正在使用 Google 地图作为其标准地图源。

目前,ggmap正在连接的 Google Maps API 需要 lon/lat 坐标(例如,location = c(16.3738,48.2082)不是位置名称)和一个正常运行且已注册的 Google Maps API 密钥(您register_google(key = "...")在每个新会话中注册)才能获取地图。

所以,你的完整代码是

library(ggmap)
register_google(key = "...") # with your billing-enabled API key entered here
map <- get_map(location = c(31.2357,30.0444), zoom = 5)
ggmap(map)

埃及情节

有关进一步的故障排除指示,请参阅Github 上的此问题


推荐阅读