New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

get_map ignores the source argument #51

Closed
grialex opened this Issue Feb 11, 2015 · 78 comments

Comments

Projects
None yet
@grialex

grialex commented Feb 11, 2015

I am trying to grab a map like this:

get_map(location = c(6.815375, 51.217942), zoom = 11, source = "osm")

Following error occures:

Error in download.file(url, destfile = destfile, quiet = !messaging, mode = "wb") :
can't open URL 'http://maps.googleapis.com/maps/api/staticmap?center=51.217942,6.815375&zoom=11&size=%20640x640&maptype=terrain&sensor=false'

And an additional warning:

W
In download.file(url, destfile = destfile, quiet = !messaging, mode = "wb") :
cannot open: HTTP status was '403 Forbidden'

Why does ggmap query google, although source is set to "osm" ? And why is the status 403 forbidden?

@jtdoud

This comment has been minimized.

jtdoud commented Feb 24, 2015

I also have similar issues:

base <- get_map(location = center, zoom= 10, source = "stamen", maptype = "watercolor")

Map from URL : http://maps.googleapis.com/maps/api/staticmap?center=49.22741,-122.8735&zoom=10&size=%20640x640&maptype=terrain&sensor=false
Google Maps API Terms of Service : http://developers.google.com/maps/terms
Error in readPNG(destfile) : file is not in PNG format

@dkahle

This comment has been minimized.

Owner

dkahle commented Feb 24, 2015

the first problem looks like an internet error, sometimes the stamen servers are down/don't respond, and you get that 403 error. the second is actually due to the current cran version, just do the below and rerun:

library(devtools)
install_github("dkahle/ggmap")
library(ggmap)

@dkahle dkahle closed this Feb 24, 2015

@dkahle

This comment has been minimized.

Owner

dkahle commented Feb 24, 2015

oh, and for why ggmap queries google for osm: it needs to get the spatial coordinates of the query.

@deltoroi

This comment has been minimized.

deltoroi commented Jul 23, 2018

Getting a similar error with get_map, Im unable to find any supporting info. This code worked well just a month ago:
My code:

atw<- get_map(location=c(-88.68,42.14), zoom=10, scale=2)
atw<-ggmap(atw)

Error:

  cannot open URL 'https://maps.googleapis.com/maps/api/staticmap?center=texas&zoom=6&size=640x640&scale=2&maptype=terrain&language=en-EN&key=AIzaSyB8GaTLxSuCRsFE55WZ0O4q63fzy9NhFDs'```
@samistat08

This comment has been minimized.

samistat08 commented Sep 12, 2018

Same problem here today. Is there any solution to this? I am using "google" as source. The code worked till yesterday!

@dkahle

This comment has been minimized.

Owner

dkahle commented Sep 12, 2018

Have you tried installing the GitHub version of ggmap? The CRAN version is quite old...

@ZachNikolakis

This comment has been minimized.

ZachNikolakis commented Sep 19, 2018

I experienced the same thing. My code worked two weeks ago but now I get the same error as above. I also installed the GitHub version of ggmap.

@dkahle

This comment has been minimized.

Owner

dkahle commented Sep 19, 2018

Sorry about that. Try installing from the tidyup branch on GitHub and check back in.

@statshermit

This comment has been minimized.

statshermit commented Sep 19, 2018

same problem here and I have a public presentation tomorrow :(
My code was working fine until yesterday and I am using the latest GitHub version of ggmap. What do you mean by "Try installing from the tidyup branch on GitHub"? I search for tidyup github dkahle but find nothing. Help?

@statshermit

This comment has been minimized.

statshermit commented Sep 19, 2018

My API is registered using register_google (key=.....) and it is showing fine with ggmap_credentials().

Here is my error message:

Error in download.file(url, destfile = destfile, quiet = !messaging, mode = "wb") :
cannot open URL 'https://maps.googleapis.com/maps/api/staticmap?center=-44.395,171.23&zoom=12&size=640x640&scale=2&maptype=terrain&language=en-EN&key=A...g_'
In addition: Warning message:
In download.file(url, destfile = destfile, quiet = !messaging, mode = "wb") :
cannot open URL 'https://maps.googleapis.com/maps/api/staticmap?center=-44.395,171.23&zoom=12&size=640x640&scale=2&maptype=terrain&language=en-EN&key=A...g_
': HTTP status was '403 Forbidden'

@dkahle

This comment has been minimized.

Owner

dkahle commented Sep 19, 2018

This works just fine for me:

if(!requireNamespace("devtools")) install.packages("devtools")
devtools::install_github("dkahle/ggmap", ref = "tidyup")
ggmap(get_googlemap())
register_google(key = "my_google_key_here")
geocode("waco texas")
@statshermit

This comment has been minimized.

statshermit commented Sep 19, 2018

It works!!!! THANK YOU so much dkahle

I ran your code above and still got similar error message but once I restart R it works. A big sight of relieve here. Thank you. Appreciate your prompt help here

@dkahle

This comment has been minimized.

Owner

dkahle commented Sep 19, 2018

Happy to help. With the accumulated changes in ggplot2 and elsewhere, ggmap (badly) needs to be updated on CRAN. I hope to do that soon. Until then, you can install from the GitHub repo (branch tidyup) as I showed above, and everything should work fine for you and your audience. I'm sure folks will let me know if that's not the case. :)

@HovhannesSahakyan

This comment has been minimized.

HovhannesSahakyan commented Sep 20, 2018

Hello dkahle,

Can't get the map. Can you please help?

Error in download.file(url, destfile = destfile, quiet = !messaging, mode = "wb") :
cannot open URL 'https://maps.googleapis.com/maps/api/staticmap?center=Kazakhstan&zoom=3&size=640x640&scale=2&maptype=terrain&style=feature:administrative.country%7Celement:labels%7Cvisibility:off&key=65492'
In addition: Warning message:
In download.file(url, destfile = destfile, quiet = !messaging, mode = "wb") :
cannot open URL 'https://maps.googleapis.com/maps/api/staticmap?center=Kazakhstan&zoom=3&size=640x640&scale=2&maptype=terrain&style=feature:administrative.country%7Celement:labels%7Cvisibility:off&key=65492': HTTP status was '403 Forbidden'

@statshermit

This comment has been minimized.

statshermit commented Sep 20, 2018

dharle,

sorry to bother you again but I manage to get 8 hours of work today with ggmap after the fix this morning but by 4PM NZT it stops working. My API credential has to get registered again. I can call geocode but it won't allow me to use ggmap(get_googlemap()).

I have tried to run it from another location (home) in case it's my workplace's firewall or proxy issue but I still get the same problem. Help please?

The error message is as follows,

geocode("waco texas")

Source : https://maps.googleapis.com/maps/api/geocode/json?address=waco%20texas&key=AIzaSyAMV
lon lat
1 -97.14667 31.54933

ggmap(get_googlemap(center=c(lon=-97.14667,lat=31.54933)))

Error in download.file(url, destfile = destfile, quiet = !messaging, mode = "wb") :
cannot open URL 'https://maps.googleapis.com/maps/api/staticmap?center=31.54933,-97.14667&zoom=10&size=640x640&scale=2&maptype=terrain&key=AIzaSyAMV'
In addition: Warning message:
In download.file(url, destfile = destfile, quiet = !messaging, mode = "wb") :
cannot open URL 'https://maps.googleapis.com/maps/api/staticmap?center=31.54933,-97.14667&zoom=10&size=640x640&scale=2&maptype=terrain&key=AIzaSyAMV': HTTP status was '403 Forbidden'

@dkahle

This comment has been minimized.

Owner

dkahle commented Sep 20, 2018

@HovhannesSahakyan – I don't know what code you entered to get the resulting error, but your message appears effectively identical to that of @statshermit below, so see the response there. Does a more basic call work? (That is, can you get a map from Google at all?)

@statshermit – Unfortunately I don't think I can help on this one since the server is rejecting your HTTP request. Since you're giving your API key, changing your (WAN-side) IP address won't matter – they can still identify you. Waiting a while and trying again may be your only real option?

@HovhannesSahakyan

This comment has been minimized.

HovhannesSahakyan commented Sep 20, 2018

@phd-project

This comment has been minimized.

phd-project commented Sep 20, 2018

@statshermit (@dkahle)

I had the same error code. Here's what worked for me. Go to your google cloud console, and enable Google Maps Static API. It looks like Google's changed stuff recently, and that function requires enabling the map API, separate from, and in addition to, enabling the geocoding API. That could explain why geocoding works for you, while grabbing the map doesnt. Good luck

@statshermit

This comment has been minimized.

statshermit commented Sep 21, 2018

@phd-project

You are right! I can call googlemap again. Thanks so much for sharing. I so appreciate everyone's help - thumbs up to everyone!

@jhongajardo

This comment has been minimized.

jhongajardo commented Sep 26, 2018

oohhhh @phd-project thank you very much for sharing the solution to this problem.
I have again the googlemap on my graphics!

<))))°>

@emilydinh

This comment has been minimized.

emilydinh commented Sep 28, 2018

Hi everyone,

I'm new to ggmap, so pardon me if I'm making ignorant beginner's mistakes. It seems I can't get anything from ggmap to work for me. Below, I show the errors I'm getting past using @dkahle 's code for installing from the tidyup GitHub branch. I've tried installing/re-installing both the CRAN and GitHub versions then restarting R several times already, and I get the same errors with the CRAN version.

ggmap(get_googlemap())

Error in download.file(url, destfile = destfile, quiet = !messaging, mode = "wb") :
cannot open URL 'https://maps.googleapis.com/maps/api/staticmap?center=29.763284,-95.363271&zoom=10&size=640x640&scale=2&maptype=terrain&key=...'
In addition: Warning message:
In download.file(url, destfile = destfile, quiet = !messaging, mode = "wb") :
cannot open URL 'https://maps.googleapis.com/maps/api/staticmap?center=29.763284,-95.363271&zoom=10&size=640x640&scale=2&maptype=terrain&key=...': HTTP status was '403 Forbidden'

register_google(key = "...")

geocode("waco texas")

Source : https://maps.googleapis.com/maps/api/geocode/json?address=waco%20texas&key=...
lon lat
1 NA NA
Warning message:
geocode failed with status OVER_QUERY_LIMIT, location = "waco texas" `

Then I test that my API is registered with ggmap_credentials. Seems fine, I think.

ggmap_credentials()

Google -
key : ...
account_type : standard
day_limit : 2500
second_limit : 50
client :
signature : `

Then I try get_map().

test1 <- get_map(location = "Texas")

Error in download.file(url, destfile = destfile, quiet = !messaging, mode = "wb") :
cannot open URL 'https://maps.googleapis.com/maps/api/staticmap?center=Texas&zoom=10&size=640x640&scale=2&maptype=terrain&language=en-EN&key=...'
In addition: Warning message:
In download.file(url, destfile = destfile, quiet = !messaging, mode = "wb") :
cannot open URL 'https://maps.googleapis.com/maps/api/staticmap?center=Texas&zoom=10&size=640x640&scale=2&maptype=terrain&language=en-EN&key=...': HTTP status was '403 Forbidden'

I checked whether I enabled the Google Maps Static & Geocoding APIs as @phd-project suggested, then tried the code above again. Yep they were enabled, but still no go. @HovhannesSahakyan mentioned needing a "real" key? What does that mean? Paying Google for a key and therefore paying to use ggmap?

I've been stuck on this for 2 days now, so I'm not sure what else to try. Please help!

@dkahle

This comment has been minimized.

Owner

dkahle commented Sep 28, 2018

Hi @emilydinh – I just pushed some changes to get_googlemap(). Try this: re-install from GitHub with devtools::install_github("dkahle/ggmap", ref = "tidyup"), reboot R, load ggmap, load in your API key, then try ggmap(get_googlemap()). Does that work?

Note: be sure to clean your GitHub post of your private API key.

@jhongajardo

This comment has been minimized.

jhongajardo commented Sep 28, 2018

Hi @emilydinh, please watch next link #51 (comment).
I Hope It is of your help..

@statshermit (@dkahle)

I had the same error code. Here's what worked for me. Go to your google cloud console, and enable Google Maps Static API. It looks like Google's changed stuff recently, and that function requires enabling the map API, separate from, and in addition to, enabling the geocoding API. That could explain why geocoding works for you, while grabbing the map doesnt. Good luck

@emilydinh

This comment has been minimized.

emilydinh commented Sep 28, 2018

Hi @dkahle,

Ah, looks like I was too quick copying and pasting in my first post. Thanks! And your solution somewhat worked...? I haven't had anything show up in the plot area before, so this is progress!

get_googlemap

Then I tried get_map again just to see what would happen. I got a different error than last time: error in data.frame vs. error in download.file

get_map(location = "Texas")

Source : https://maps.googleapis.com/maps/api/staticmap?center=Texas&zoom=10&size=640x640&scale=2&maptype=terrain&language=en-EN&key=...
Source : https://maps.googleapis.com/maps/api/geocode/json?address=Texas&key=...
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 OVER_QUERY_LIMIT, location = "Texas"

Thanks for your quick response! Let me know what the next step is.

@emilydinh

This comment has been minimized.

emilydinh commented Sep 28, 2018

Hi @jhongajardo,

I said in my first post that I already tried @phd-project's solution. I just checked again that the APIs are enabled, and they are.

Thanks for your help!

@dkahle

This comment has been minimized.

Owner

dkahle commented Sep 28, 2018

@emilydinh : Remember that the output contains your private API key. :)

When you copy/paste the URL into the browser, what happens?

@emilydinh

This comment has been minimized.

emilydinh commented Sep 28, 2018

@dkahle: Ah, you are right about the key in the output. Anyways, the URL sends me to a webpage version of the plot error.

image

@dkahle

This comment has been minimized.

Owner

dkahle commented Sep 28, 2018

I just pushed minor things, try to get those, but I don't expect a change.

I previously got what Google's giving you when I wasn't supplying an API key, but I can't reproduce the problem now. I can't reproduce yours, either. Obviously, something is wrong with the API part - is it the URL ggmap is making? (maybe), is it a mistyped API key? (probably not), is it some other environmental assumption? I don't know. The geocode error is obvious, but I don't think that's causing the problem. What seems pretty clear: if you can load the URL in the browser, the R side stuff should work just fine.

To be clear, when, in a fresh R session, I load ggmap, register my Google API key with register_google(), and run ggmap(get_googlemap()), it works just fine.

@emilydinh

This comment has been minimized.

emilydinh commented Sep 28, 2018

Hi @dkahle, I don't think I've mistyped my API key because I copied and pasted it straight from Google. I've tried your solution with a new R session several times, but still get the same issues. Is there anything else I can do?

@alis486

This comment has been minimized.

alis486 commented Oct 11, 2018

This has seemed to work. However I am now having an error knitting to a word document

Error in get-googlemap(centre = location, zoom = zoom, maptype = maptype, : Forbidden (Http 403). get_googlemap -> stop_for_status

@dvorw

This comment has been minimized.

dvorw commented Oct 11, 2018

@kambanane

This comment has been minimized.

kambanane commented Oct 11, 2018

Ugh, this is incredibly frustrating. Like the above poster, I cannot get this to work.

I enabled billing and got a key, have successfully registered the key using register_google()

Tried my code and get this:

eth_basemap <- ggmap::get_map(location="Chicago", zoom=11, source="osm")
Source : https://maps.googleapis.com/maps/api/staticmap?center=Chicago&zoom=11&size=640x640&scale=2&maptype=terrain&key=XXXX
Source : https://maps.googleapis.com/maps/api/geocode/json?address=Chicago&key=XXXX
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 = "Chicago"

@dkahle

This comment has been minimized.

Owner

dkahle commented Oct 11, 2018

Sorry for the frustrations; I'm working to resolve the issues. Do know that source="osm" will not work, see #117.

@kambanane

This comment has been minimized.

kambanane commented Oct 11, 2018

Thanks. With or without source="osm" it does not work:

eth_basemap <- ggmap::get_map(location="Chicago", zoom=11)
Source : https://maps.googleapis.com/maps/api/staticmap?center=Chicago&zoom=11&size=640x640&scale=2&maptype=terrain&language=en-EN&key=XXXX
Source : https://maps.googleapis.com/maps/api/geocode/json?address=Chicago&key=XXXX
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 = "Chicago"

@dkahle

This comment has been minimized.

Owner

dkahle commented Oct 11, 2018

Hm. Works for me. Try enabling the Geocoding API in the Google Cloud Platform manager?

@kambanane

This comment has been minimized.

kambanane commented Oct 11, 2018

Oh praise Cthulhu. It worked.

Thank you so much.

Repository owner deleted a comment from statshermit Oct 11, 2018

@arne1921KF

This comment has been minimized.

arne1921KF commented Oct 12, 2018

FTR, you need to provide a credit card to enable billing in Google Cloud Platform. Also, as per the services terms, the free trial period ends either after 12 months or after reaching your credit level of 300$.

From the Supplemental TOS:
1.3 The Free Trial starts when Customer creates a billing account in the Google Cloud Console (“Free Trial Start Date”) and ends on the earlier of (i) the date that Customer’s fees for usage exceeds $300 or (ii) 12 months from the Free Trial Start Date.,

Bottom line: those without a credit card, like me, are apparently now excluded from using Google Maps within R.

@kambanane

This comment has been minimized.

kambanane commented Oct 12, 2018

@dkahle

This comment has been minimized.

Owner

dkahle commented Oct 13, 2018

@arne1921KF, @kambanane – I'm sorry for the frustration. To be clear: this was not a change in ggmap, but Google's web API. ggmap simply facilitates the connection between R and various Google services; it has no control over either.

@dvorw

This comment has been minimized.

dvorw commented Oct 13, 2018

@arne1921KF

This comment has been minimized.

arne1921KF commented Oct 13, 2018

@grafau

This comment has been minimized.

grafau commented Oct 15, 2018

Hi!

So, I have done all of the above: enabled billing, static map api, geocoding api, got key, installed ggmap from 'tidy' branch.
I load library:

library(ggmap)
Loading required package: ggplot2
Google Maps API Terms of Service: http://developers.google.com/maps/terms.
Please cite ggmap if you use it: see citation('ggmap') for details.
Warning message:
package ‘ggplot2’ was built under R version 3.4.2

Now that is the kicker: whenever I try to register_google, I get following:
register_google(key)

Error in register_google(key) : could not find function "register_google"

And of course, when trying to get_map:

I get:

HTTP status was '403 Forbidden'

Any ideas? Many thanks!

Rafal

@dkahle

This comment has been minimized.

Owner

dkahle commented Oct 15, 2018

@grafau : If register_google() isn't found, sounds like the install from GitHub didn't work. Or, it could be that it did, but you didn't restart R and reload the newer ggmap. I would just run by that again and make sure things are going as you expect. (And maybe update ggplot2?)

@dvorw

This comment has been minimized.

dvorw commented Oct 16, 2018

@simonberrebi

This comment has been minimized.

simonberrebi commented Oct 16, 2018

Hey all,

This is a really cool tool, thanks to everyone who contributed! However, I'm having the same issue. I added my credit card info and register_google'ed. When I tried to get_map, I got the following error message:

Source : https://maps.googleapis.com/maps/api/staticmap?center=Europe&zoom=4&size=640x640&scale=2&maptype=terrain&language=en-EN&key=xxx*
Error in get_googlemap(center = location, zoom = zoom, maptype = maptype, :
Forbidden (HTTP 403).

  • with the link pointing to a page saying: "The Google Maps Platform server rejected your request. This API project was not found. This API project may have been deleted."

Then I enabled APIs through Google API's library (Places API, MAP Static API, and Roads API). It still doesn't work but I get a different message with no 403 (see below). Could the issue be that were missing some APIs? If so, which ones should be enabled?

Source : https://maps.googleapis.com/maps/api/staticmap?center=42.14,-88.68&zoom=10&size=640x640&scale=2&maptype=terrain&language=en-EN&key=xxx*
1280x1280 terrain map image from Google Maps. see ?ggmap to plot it.

@petersoapes

This comment has been minimized.

petersoapes commented Oct 18, 2018

Hi all
Following some of the suggestions on this chain I was able to get ggmap working again on my laptop (yay!). this is what I ran
if(!requireNamespace("devtools"))install.packages("devtools")
devtools::install_github("dkahle/ggmap", ref = "tidyup")
then I linked my billing enabled API key with register_google(), and it worked.

When I've tried to replicate this on my work computer, I can't get ggmaps to load. I get the following error when trying to run the dev::tools_install_github()

Loading required package: ggplot2
Error in loadNamespace(i, c(lib.loc, .libPaths()), versionCheck = vI[[i]]) :
namespace ‘stringi’ 1.1.2 is being loaded, but >= 1.1.6 is required
Error: package or namespace load failed for ‘ggmap’

@dkahle

This comment has been minimized.

Owner

dkahle commented Oct 18, 2018

Hi @petersoapes – looks like you need to update stringi:

install.packages("stringi")

Give that a shot and retry.

@petersoapes

This comment has been minimized.

petersoapes commented Oct 21, 2018

Thanks, that worked.
The second time I installed "stringi" and then did the rest of the steps, it worked. I think I may have not been resatrting my R session correctly.

@g-mann

This comment has been minimized.

g-mann commented Oct 24, 2018

Super appreciative of all the help posted here (particularly @dkahle and @RomanAbashin)...THANKS!!!

I was having similar problems with a recurring 403 problem when trying to use get_map with source="google". I had installed the dkahle/ggmap from the tidyup branch and got the API key/billing sorted out with google. However, despite having enable both the Geocoding and Maps Static APIs, only the former was working (i.e., I was getting the "Waco, Texas" coordinates, but couldn't get a map). I noticed on the Google dashboard that the Geocoding API was getting some traffic (every time I tried it), but that the Maps Static API wasn't showing anything. I eventually regenerated the API key and it all worked. Just thought this might help someone else.

@sarahkaunitz

This comment has been minimized.

sarahkaunitz commented Nov 29, 2018

Hi @dkahle
You seem very knowledgeable about retrieving and making all these google maps. I am trying to get a map in R and am getting this error.

sfmap <- qmap("San Francisco", zoom = 12, type = "roadmap")

cannot open URL 'http://maps.googleapis.com/maps/api/staticmap?center=San+Francisco&zoom=12&size=640x640&scale=2&maptype=terrain&language=en-EN&sensor=false': HTTP status was '403 Forbidden'Error in download.file(url, destfile = tmp, quiet = !messaging, mode = "wb") :
cannot open URL 'http://maps.googleapis.com/maps/api/staticmap?center=San+Francisco&zoom=12&size=640x640&scale=2&maptype=terrain&language=en-EN&sensor=false'

Do you think you could help me figure out what I need to do for it to work?
Thanks in advance!

@dkahle

This comment has been minimized.

Owner

dkahle commented Nov 29, 2018

Hi @sarahkaunitz

After re-installing the dev version of ggmap (see above), and going on Google Cloud's manager and enabling the Maps Static and Geocoding APIs along with billing, try:

sfmap <- get_googlemap("san francisco", zoom = 12, type = "roadmap")
ggmap(sfmap)
@sabahzero

This comment has been minimized.

sabahzero commented Nov 30, 2018

Hi all,
I am trying everything for hours and nothing has worked, halp!
I have my Google API code and it shows as registered in R

I first tried
devtools::install_github("hadley/ggplot2")
devtools::install_github("dkahle/ggmap")

I then tried the suggested example
if(!requireNamespace("devtools")) install.packages("devtools")
devtools::install_github("dkahle/ggmap", ref = "tidyup")
ggmap(get_googlemap())
register_google(key = "keyhere")
geocode("waco texas")

Again and again and again the error keeps coming up as
"Error in get_googlemap() : Forbidden (HTTP 403)"
I've looked up how to get around this without luck.

All I want to do is plot lat and lon points corresponding to my dataset to a map in R
If it helps, here's a previous example code that was working in May but isn't anymore (because of the API, I suppose?): https://github.com/sabahzero/MicrobialEcology_AmpliconSeqWorkflow_UlHasanetal/tree/master/v1_May15-2018

Very very many thanks in advance 🙏

@full6186

This comment has been minimized.

full6186 commented Dec 5, 2018

Hello everyone.
I just wanted to give the problem I had and what I did to solve it for any newcomers to this ever growing feed. For me, I was getting the 'Forbidden (HTTP 403) error that many were having in an old code I used for a manuscript. I followed the solutions found in this comment overflow but more closely to @RomanAbashin's (Sept 30th) (Link here: #51 (comment)) nicely detailed summary comment as follows:
Note: It's imperative to do these in the proper steps -- I think that is why some are having issues with individual steps despite doing all that has been suggested! For me, it worked the first time.

Google Cloud Console (before doing anything in R):

  1. First I registered an API key within the Google Cloud console following the link provided from @RomanAbashin -- I did not restrict the API key as suggested by Google (does anyone have any advice on this moving forward? I'd like to make it as secure as possible -- but still have it usable). I also made sure billing was turned on as suggested in many other posts -- it's free unless you are using it to pull large quantities of maps, but they want a credit card to 'make sure you aren't a robot'.
  2. You will need to create a new project
  3. Next, search for and enable the 'Geocoding API' and the 'Maps Static API'
    From your Google Cloud Page Click 'APIs and Services' >> Library >> (To Filter: look in the left hand column under Category and scroll down to 'Maps' -- Click it >> Geocoding API should be in the first row (Enable It). (Repeat for 'Maps Static API', which is in the 3rd row)
  4. From the 'Credentials' menu you can Copy your API key to the clipboard.

Onward to R!

  1. I reinstalled ggmap using @dkahle code here: (Link: #51 (comment)) :
    devtools::install_github("dkahle/ggmap", ref = "tidyup")
  2. I rebooted R
  3. Loaded ggmap library (copy-paste API from Google Cloud Console):
    library(ggmap)
    register_google(key = 'copy-API-key-from-GoogleConsole')
  4. Run my code again. It works!

@sabahzero have you had any luck over the last few days?
From your code linked above on your github:
# Create zoomed-in map (main figure) Zoom=get_map(location=c(-116.9685,32.22644,-116.9241,32.26755), maptype="roadmap")
Sidenote: I didn't change my command for 'get_map()' as suggested in some other posts and it still works for me. I think if you can do all that is required for the API steps and register it, reinstall ggmap with the above command, reboot R, load ggmap, register your API key, and rerun your code you should have success!

Try following my steps listed above or visit @RomanAbashin's comment that I linked to. He has a link to Google's page with info about properly setting up your API with billing and all.

After writing this, I dug through the comments more and I see much of this is also summarized here:
(#51 (comment)).

Thanks much to @dkahle & @RomanAbashin! Plus many others who have been troubleshooting! You made this one easy for me to fix with manuscript reviews due in a couple of days!

@dvorw

This comment has been minimized.

dvorw commented Dec 5, 2018

@lgellis

This comment has been minimized.

lgellis commented Dec 10, 2018

For those who it might help, I updated my ggmap tutorial to include the google cloud platform steps with screenshots to create the service, get an api key and apply it. https://www.littlemissdata.com/blog/maps

@dkahle thank you so much for your awesome package and all the support you've been giving. @full6186 great summary above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment