Error in get_map using ggmap in R
Asked Answered
O

3

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'

Oxeyed answered 7/11, 2013 at 3:40 Comment(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?Elevator
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...Oxeyed
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.Elevator
J
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=_

Jodiejodo answered 16/11, 2017 at 20:54 Comment(1)
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.Marleenmarlen
M
3

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

Maniemanifest answered 2/10, 2018 at 16:18 Comment(1)
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 for clarity. @sarah-grogan I doubt it will be free for very long though...Dicks
C
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.

Chestonchest answered 26/3, 2017 at 11:39 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.