【问题标题】:geocode failed with status REQUEST_DENIED, location = "Australia" using ggmap in R地理编码失败,状态为 REQUEST_DENIED,位置 =“澳大利亚”,在 R 中使用 ggmap
【发布时间】:2018-11-17 06:51:33
【问题描述】:

我正在尝试使用邮政编码和净值在澳大利亚制作密度图,以了解客户来自哪里机场停车场(大学项目)

我已经为谷歌地图设置了一个 API 密钥。我正在使用 ggmap,但不断收到 request denied 错误。

Source : https://maps.googleapis.com/maps/api/staticmap?center=Gold%20Coast&zoom=12&size=640x640&scale=2&maptype=terrain&key=xxx
Source : https://maps.googleapis.com/maps/api/geocode/json?address=Gold%20Coast&key=xxx
Error in data.frame(ll.lat = ll[1], ll.lon = ll[2], ur.lat = ur[1], ur.lon = ur[2]) : 
  arguments imply differing number of rows: 0, 1
In addition: Warning message:
geocode failed with status REQUEST_DENIED, location = "Australia" 

我已经尝试了几种检索地图数据的方法,但总是遇到同样的错误。

请帮助 :) 任何建议表示赞赏!另外,如果有更好的方法建议,我会全神贯注:)

这里是使用的代码:

if(!requireNamespace("devtools")) install.packages("devtools")
devtools::install_github("dkahle/ggmap", ref = "tidyup")
library("ggmap", lib.loc="C:/Program Files/Microsoft/R Open/R-3.5.0/library")


key <- register_google(key = "###API KEY###")


    p <- ggmap(get_googlemap(center = "Australia", source = 'google', 
                             zoom = 11, scale = 2,
                             maptype ='terrain',
                             color = 'color'))
    p + geom_point(aes(x = hmapf$Postcode, y = hmapf$`Net Value`,  colour = "Pink"), data = hmapf, size = 0.5) + 
      theme(legend.position="bottom"); p

我还尝试了另一种方法:

Australia <- get_map(location="Australia", zoom=3, maptype="terrain")

gg <- ggmap(Australia, extent="normal")
gg <- gg + geom_point(data=pop, aes(x=LONG, y=LAT, color=Density))
gg <- gg + scale_color_viridis()
gg <- gg + theme_map()
gg <- gg + theme(legend.position="none")
gg

我没有任何运气,两者都有同样的错误。 谢谢:)

【问题讨论】:

  • 必须是静态地图还是交互式地图?
  • 您可能滥用免费套餐,请求过多,并输入了无效的帐单卡。等一三天。
  • 您应该将您的项目与结算帐户相关联,或者您每天只能使用该 API 一次
  • @SymbolixAU - 当然地图可以是静态的
  • @hrbrmstr 谢谢,但是这个错误从 API 上线的那一刻起就发生了。在谷歌控制台中,它显示 API 正在触发并且请求已成功。

标签: r ggplot2 ggmap


【解决方案1】:

地理编码失败,状态为 REQUEST_DENIED,位置 =“XXX”

您已为静态地图请求启用 Google Maps API,但未启用地理编码。为了证明尝试geocode("Australia", output = "all")会报错

$`error_message`
[1] "This API project is not authorized to use this API."

$results
list()

$`status`
[1] "REQUEST_DENIED"

See also this step-by-step tutorial how make ggmap work in 2018..

【讨论】:

  • 感谢罗曼!我确实发现问题出在地理编码上,所以我更改了它并最终使用了完美的长/纬度坐标。我尝试了几种使用地理编码功能的方法,但一直出错。现在我知道问题出在哪里了。我将更改 google API 中的设置以允许地理编码,我不知道这是一个特定选项,我认为问题可能出在函数中。感谢您为我解决这个问题,我很感激!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-10-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-07-28
相关资源
最近更新 更多