26

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'

rcs
  • 67,191
  • 22
  • 172
  • 153
user2861089
  • 1,205
  • 4
  • 22
  • 44
  • 9
    You could take a look at the Google API for potential causes for the 403 errors: https://developers.google.com/maps/documentation/business/articles/usage_limits#http403. 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 Nov 07 '13 at 04:31
  • 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 Nov 08 '13 at 05:10
  • 3
    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 Nov 08 '13 at 05:47

3 Answers3

6

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=_

Steen Harsted
  • 1,802
  • 2
  • 21
  • 34
  • You must be aware that using the API incurs charges that will be deducted from your credit card which is required for registration in Google Cloud. – Agile Bean Nov 23 '18 at 01:27
3

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

Sarah Grogan
  • 117
  • 1
  • 9
  • You must include API Key with your request (and have Billing enabled) to produce any maps with ggmap in R. See [the official ggmap repository](https://github.com/dkahle/ggmap) for clarity. @sarah-grogan I doubt it will be __free__ for very long though... – SilSur Oct 24 '18 at 11:06
2

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.

heights1976
  • 480
  • 6
  • 16