使用R中的ggmap,地址解析失败,状态为REQUEST_DENIED,位置=“澳大利亚”

时间:2018-11-17 06:51:33

标签: r ggplot2 ggmap

我正在尝试使用邮政编码和净值在澳大利亚绘制密度图,以查看机场停车场的客户来自何方(大学项目)

我已经为Google地图设置了API密钥。我正在使用ggmap,但始终收到请求被拒绝的错误。

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

我没有运气,两个都犯同样的错误。 谢谢:)

1 个答案:

答案 0 :(得分: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.