26
votes

About 90% of the time, when using get_map in ggmap, I get the following error. Can someone please tell me why?

map <- get_map(location = 'Australia', zoom = 4)

Error in download.file(url, destfile = destfile, quiet = !messaging, mode = "wb") : cannot open URL 'http://maps.googleapis.com/maps/api/staticmap?center=Australia&zoom=4&size=%20640x640&scale=%202&maptype=terrain&sensor=false' In addition: Warning message: In download.file(url, destfile = destfile, quiet = !messaging, mode = "wb") : cannot open: HTTP status was '403 Forbidden'

3
You could take a look at the Google API for potential causes for the 403 errors: developers.google.com/maps/documentation/business/articles/…. The typical cause seems to be that you've exceeded the daily limits for the API. For what it's worth, I was able to copy the link above, put it into my web browser, and successfully get an image of Australia returned...are you generating 1000s of requests per day that are maxing out the API?Chase
Thanks for your comment. No, I'm only trying a couple of times so there's no way I should be maxing out the API...user2861089
Hmm, I wonder if it's something wonky with your IP address or something? Are you logging in from a big office/university or where other computers would be assigned the same IP address? That's a complete and total WAG, but I'd put my money on something with your computer, firewall, or IP address getting in the way. You could try from a different computer and / or internet connection to test that theory.Chase
Thanks a lot for your suggestions.user2861089

3 Answers

6
votes

The problem is likely related to your API project not being authorized by Google.

An API project is easy to create, and get authorized:
Click this link and choose create. Alternatively choose select if you already have a created project, but just need to activate the API. After that choose "Enable". After that your code should work.

Link again: https://console.developers.google.com/apis/api/static_maps_backend?project=_

3
votes

The 403 error is because Google now requires users to register for and use a (free) api key.

2
votes

The "zoom = 4" is, per documentation, "reserved for google business users only." I can't find much documented on why this would work intermittently or at all for a non-business user, but that's my best guess.