ggmap 中的错误,“必须是一个数组"和“HTTP 400 错误请求" [英] Error in ggmap, "must be an array" and "HTTP 400 bad request"

查看:29
本文介绍了ggmap 中的错误,“必须是一个数组"和“HTTP 400 错误请求"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 ggmap 从谷歌地图调用地图.示例代码:

I'm trying to call a map from google maps using ggmap. Example code:

get_googlemap(center = c(lon = -56.67, lat = 51.47), zoom = 8, size = c(640, 640), scale = 2,
                   format = "png8", maptype = "satellite")

但是,这会返回以下错误:

However, this returns the following error:

来源:https://maps.googleapis.com/maps/api/staticmap?center=24.8,-81.7&zoom=8&size=640x640&scale=4&maptype=satellite&;key=(删除发布键)

Error in aperm.default(map, c(2, 1, 3)) : 
  invalid first argument, must be an array
In addition: Warning message:
In get_googlemap(center = c(lon = -81.7, lat = 24.8), zoom = 8,  :
  HTTP 400 Bad Request

我查看了人们遇到类似问题的线程.在对 API 密钥和限制进行一些摆弄之后,它们似乎得到了解决.在这种情况下,我做了以下事情:

I have looked at threads where people are experiencing similar problems. It appears they were resolved after some fiddling with the API key and restrictions. I have done the following things in that context:

  1. 启用计费
  2. 限制了我的 API 密钥 - 但是,我没有选择将其限制为静态地图".我目前将其限制为谷歌云 API".和以前一样的错误,但关键仍然是注册命中.
  3. 完成上述操作后重新启动 R,并仔细检查我的包.

希望得到一些帮助,我的实验室同学都没有遇到这个问题,我开始把头发扯掉,哈哈.

Would appreciate some help with this, none of my labmates are having this problem and I'm starting to tear my hair out, lol.

推荐答案

经过一番折腾,我想通了.它不是非常直观,所以我把它贴在这里以防其他新人遇到同样的问题.

After some messing around, I figured it out. It wasn't extremely intuitive, so I'm posting it here in case someone else who is new runs into the same problem.

本质上,生成密钥后,从云控制台,您需要进入库并启用以下四个 API:

Essentially, after generating the key, from the cloud console, you need to go into the library and enable the following four APIs:

静态地图,地图嵌入,地理位置,地理编码.

Static Maps, Map Embed, Geolocation, Geocoding.

然后,去编辑密钥.向下滚动并将其限制为上述四个 API.在那之后工作得很好.

Then, go edit the key. Scroll down and restrict it to the aforementioned four APIs. Worked perfectly fine after that.

这篇关于ggmap 中的错误,“必须是一个数组"和“HTTP 400 错误请求"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆