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:
Source : https://maps.googleapis.com/maps/api/staticmap?center=24.8,-81.7&zoom=8&size=640x640&scale=4&maptype=satellite&key=(removed key for posting)
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
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:
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.
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.
Then, go edit the key. Scroll down and restrict it to the aforementioned four APIs. Worked perfectly fine after that.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With