I'm trying to do a density map in Australia using postcodes and net value to see where customers are coming from for an airport carpark (University Project)
I have setup an API key for google maps. I am using ggmap but keep getting request denied error.
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"
I have tried several methods of retrieving the map data, however keep getting same error.
Please help :) Any advice is appreciated! Also if there are suggestions for a better way of doing this, I'm all ears :)
here is code used:
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
I also tried another method:
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
I am not having any luck, same error for both. Thanks :)
geocode failed with status REQUEST_DENIED, location = "XXX"
You have enabled your Google Maps API for static map requests, but not for geocoding. To prove that try geocode("Australia", output = "all")
and you will get the error
$`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..