dkahle / ggmap

A package for plotting maps in R with ggplot2
766 stars 231 forks source link

get_map ignores the source argument #51

Closed grialex closed 9 years ago

grialex commented 9 years ago

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 commented 9 years ago

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 commented 9 years ago

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 commented 9 years ago

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

deltoroi commented 6 years ago

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 commented 6 years ago

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

dkahle commented 6 years ago

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

ZachNikolakis commented 6 years ago

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 commented 6 years ago

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

statshermit commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago

@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 commented 6 years ago

Thank you very much for you kind response.

I think I know what is the problem. The problem actually is that the key is not the right key. And I need to enter some bank account number to get a real key. I am not sure I need to get maps in that way. Will try to draw my maps with other options.

Best wishes, Hovhannes

On Thursday, 20 September 2018, 16:17:01 EEST, david kahle <notifications@github.com> wrote:  

@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?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

phd-project commented 6 years ago

@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 commented 6 years ago

@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 commented 6 years ago

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

<))))°>

emilydinh commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago

Hi @emilydinh, please watch next link https://github.com/dkahle/ggmap/issues/51#issuecomment-423365552. 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 commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago

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

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

emilydinh commented 6 years ago

@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 commented 6 years ago

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 commented 6 years ago

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?

dkahle commented 6 years ago

@emilydinh sure, I just don't know if I'll be able to think of it. :)

Can you provide a small reproducible example of what's breaking without including your API key? Also, a devtools::session_info() may help.

emilydinh commented 6 years ago

@dkahle I'm not sure if I can provide a reproducible example. I've tried the same code below on 2 different computers, but got different outputs. I'll focus on one computer's issues for now. I'm not sure if this will reproduce for you, but here goes. The R plot stopped working for me when I run ggmap(get_googlemap()). The URLs still don't work in my browser.

library(ggmap) register_google(key = "...") ggmap(get_googlemap()) # Results in Forbidden (HTTP 403) error get_map(location="Texas") # Results in Forbidden (HTTP 403) error devtools::session_info()

>Session info -------------------------------------------------------------------------------------- setting value
version R version 3.4.3 (2017-11-30) system x86_64, mingw32
ui RStudio (1.1.423)
language (EN)
collate English_United States.1252 tz America/New_York date 2018-09-28

Packages -------------------------------------------------------------------------------------------- package * version date source
assertthat 0.2.0 2017-04-11 CRAN (R 3.4.3)
base * 3.4.3 2017-12-06 local bindr 0.1.1 2018-03-13 CRAN (R 3.4.4) bindrcpp 0.2.2 2018-03-29 CRAN (R 3.4.4) bitops 1.0-6 2013-08-17 CRAN (R 3.4.1) colorspace 1.3-2 2016-12-14 CRAN (R 3.4.3) compiler 3.4.3 2017-12-06 local crayon 1.3.4 2017-09-16 CRAN (R 3.4.3) curl 3.2 2018-03-28 CRAN (R 3.4.4) datasets * 3.4.3 2017-12-06 local devtools 1.13.6 2018-06-27 CRAN (R 3.4.4) digest 0.6.17 2018-09-12 CRAN (R 3.4.4) dplyr 0.7.6 2018-06-29 CRAN (R 3.4.4) ggmap * 2.7.903 2018-09-28 Github (dkahle/ggmap@3517767) ggplot2 * 3.0.0 2018-07-03 CRAN (R 3.4.4) glue 1.3.0 2018-07-17 CRAN (R 3.4.4) graphics * 3.4.3 2017-12-06 local grDevices * 3.4.3 2017-12-06 local grid 3.4.3 2017-12-06 local gtable 0.2.0 2016-02-26 CRAN (R 3.4.3) httr 1.3.1 2017-08-20 CRAN (R 3.4.3) jpeg 0.1-8 2014-01-23 CRAN (R 3.4.1) lazyeval 0.2.1 2017-10-29 CRAN (R 3.4.3) magrittr 1.5 2014-11-22 CRAN (R 3.4.3) memoise 1.1.0 2017-04-21 CRAN (R 3.4.4)
methods * 3.4.3 2017-12-06 local munsell 0.5.0 2018-06-12 CRAN (R 3.4.4)
pillar 1.3.0 2018-07-14 CRAN (R 3.4.4) pkgconfig 2.0.2 2018-08-16 CRAN (R 3.4.4)
plyr 1.8.4 2016-06-08 CRAN (R 3.4.3) png 0.1-7 2013-12-03 CRAN (R 3.4.1) purrr 0.2.5 2018-05-29 CRAN (R 3.4.4) R6 2.2.2 2017-06-17 CRAN (R 3.4.3) Rcpp 0.12.18 2018-07-23 CRAN (R 3.4.4)
RgoogleMaps 1.4.2 2018-06-08 CRAN (R 3.4.4)
rjson 0.2.20 2018-06-08 CRAN (R 3.4.4) rlang 0.2.2 2018-08-16 CRAN (R 3.4.4) rstudioapi 0.7 2017-09-07 CRAN (R 3.4.3) scales 1.0.0 2018-08-09 CRAN (R 3.4.4) stats * 3.4.3 2017-12-06 local stringi 1.1.7 2018-03-12 CRAN (R 3.4.4)
stringr 1.3.1 2018-05-10 CRAN (R 3.4.4)
tibble 1.4.2 2018-01-22 CRAN (R 3.4.3)
tidyselect 0.2.4 2018-02-26 CRAN (R 3.4.4)
tools 3.4.3 2017-12-06 local utils * 3.4.3 2017-12-06 local withr 2.1.2 2018-03-15 CRAN (R 3.4.4)
yaml 2.2.0 2018-07-25 CRAN (R 3.4.4)

rrmn commented 6 years ago

@dkahle @emilydinh Same boat, but grabbing the newest version from dkahle (link to post) really helped and I got it to function for the very first time (woohoo!). THANK YOU A LOT FOR YOUR WORK!

I'll just post the steps for anyone who is looking for a solution as well (I was in GIS and dependency hell for 2 weeks now).

1. Update to newest version of ggmap

require(devtools)
devtools::install_github("dkahle/ggmap", ref = "tidyup")

2. Load ggmap and register your Google API key

(Link for more info on how to get an API key)

library(ggmap)
register_google(key = "...")     # copied directly from Google Console via 'copy' button

3. Plot default map

ggmap(get_googlemap())           # results in below map

rplot

3. Plot with location name

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

3. Plot with lon / lat

ggmap(get_map(location=c(16.3738,48.2082), zoom=13, scale=2)) # results in below map (wohoo!)

rplot04

Check version

devtools::session_info()

Session info --------------------------------------------------------------------------------
 setting  value                       
 version  R version 3.5.1 (2018-07-02)
 system   x86_64, mingw32             
 ui       RStudio (1.1.456)           
 language (EN)                        
 collate  German_Germany.1252         
 tz       Europe/Berlin               
 date     2018-09-30                  

Packages ------------------------------------------------------------------------------------
 package     * version date       source                       
 assertthat    0.2.0   2017-04-11 CRAN (R 3.5.1)               
 base        * 3.5.1   2018-07-02 local                        
 bindr         0.1.1   2018-03-13 CRAN (R 3.5.1)               
 bindrcpp    * 0.2.2   2018-03-29 CRAN (R 3.5.1)               
 bitops        1.0-6   2013-08-17 CRAN (R 3.5.0)               
 colorspace    1.3-2   2016-12-14 CRAN (R 3.5.1)               
 compiler      3.5.1   2018-07-02 local                        
 crayon        1.3.4   2017-09-16 CRAN (R 3.5.1)               
 curl          3.2     2018-03-28 CRAN (R 3.5.1)               
 datasets    * 3.5.1   2018-07-02 local                        
 devtools    * 1.13.6  2018-06-27 CRAN (R 3.5.1)               
 digest        0.6.17  2018-09-12 CRAN (R 3.5.1)               
 dplyr         0.7.6   2018-06-29 CRAN (R 3.5.1)               
 ggmap       * 2.7.903 2018-09-30 Github (dkahle/ggmap@3517767)
 ggplot2     * 3.0.0   2018-07-03 CRAN (R 3.5.1)               
 glue          1.3.0   2018-07-17 CRAN (R 3.5.1)               
 graphics    * 3.5.1   2018-07-02 local                        
 grDevices   * 3.5.1   2018-07-02 local                        
 grid          3.5.1   2018-07-02 local                        
 gtable        0.2.0   2016-02-26 CRAN (R 3.5.1)               
 httr          1.3.1   2017-08-20 CRAN (R 3.5.1)               
 jpeg          0.1-8   2014-01-23 CRAN (R 3.5.0)               
 jsonlite      1.5     2017-06-01 CRAN (R 3.5.1)               
 labeling      0.3     2014-08-23 CRAN (R 3.5.0)               
 lazyeval      0.2.1   2017-10-29 CRAN (R 3.5.1)               
 magrittr      1.5     2014-11-22 CRAN (R 3.5.1)               
 memoise       1.1.0   2017-04-21 CRAN (R 3.5.1)               
 methods     * 3.5.1   2018-07-02 local                        
 munsell       0.5.0   2018-06-12 CRAN (R 3.5.1)               
 pillar        1.3.0   2018-07-14 CRAN (R 3.5.1)               
 pkgconfig     2.0.2   2018-08-16 CRAN (R 3.5.1)               
 plyr          1.8.4   2016-06-08 CRAN (R 3.5.1)               
 png           0.1-7   2013-12-03 CRAN (R 3.5.0)               
 purrr         0.2.5   2018-05-29 CRAN (R 3.5.1)               
 R6            2.2.2   2017-06-17 CRAN (R 3.5.1)               
 Rcpp          0.12.18 2018-07-23 CRAN (R 3.5.1)               
 RgoogleMaps   1.4.2   2018-06-08 CRAN (R 3.5.1)               
 rjson         0.2.20  2018-06-08 CRAN (R 3.5.0)               
 rlang         0.2.2   2018-08-16 CRAN (R 3.5.1)               
 rstudioapi    0.7     2017-09-07 CRAN (R 3.5.1)               
 scales        1.0.0   2018-08-09 CRAN (R 3.5.1)               
 stats       * 3.5.1   2018-07-02 local                        
 stringi       1.1.7   2018-03-12 CRAN (R 3.5.0)               
 stringr       1.3.1   2018-05-10 CRAN (R 3.5.1)               
 tibble        1.4.2   2018-01-22 CRAN (R 3.5.1)               
 tidyselect    0.2.4   2018-02-26 CRAN (R 3.5.1)               
 tools         3.5.1   2018-07-02 local                        
 utils       * 3.5.1   2018-07-02 local                        
 withr         2.1.2   2018-03-15 CRAN (R 3.5.1)               
 yaml          2.2.0   2018-07-25 CRAN (R 3.5.1)               
merijnkerstens commented 6 years ago

@emilydinh I am experiencing the exact same problem, including the fact that my maps cannot be loaded in my browser. Even when I follow @dkahle's simple instructions (loading ggmap, registering my api (I tried both old ones and newly generated ones, none seem to work) and running ggmap(get_googlemap()). My version is from GitHub and up to date - @RomanAbashin's tips return the same error...

rrmn commented 6 years ago

@Eydise I knows it’s a long shot, but would you mind double-checking the API key and running session_info()?

emilydinh commented 6 years ago

Hi @dkahle & @Eydise,

I still can't get anything from ggmap to consistently work for me. The first time I followed @RomanAbashin's tips, I succesfully plotted the default map in R with ggmap(get_googlemap()), but the browser map didn't work. Plotting with location name and lon/lat didn't work in R or the browser. I got the Forbidden (HTTP 403) error for both. To test that things would consistently work for me, I restarted R and tried plotting the default map again. That resulted in the Forbidden (HTTP 403) error. Does this have to do with API quotas?

P.S. Thanks @RomanAbashin for your thorough and straightforward troubleshoot! I really appreciate everyone's help with this!

rrmn commented 6 years ago

@emilydinh ggmap throwing inconsistent 403’s really sounds like an API key issue.

Either your API key is invalid, has no billing enabled, or something similar (and you get demoted to the free tier which sometimes works and sometimes doesn’t - that’s unfortunately normal behavior) or you hit a request quota and are 403‘d afterwards for the rest of the day (but that‘s a couple of thousand requests for that API key).

rrmn commented 6 years ago

One more thing, to the best of my knowledge:

As of now, Google Maps only accepts Lon/Lat center point (vector length =1) requests, no location names.

In contrast, OSM (source=„osm“) accepts Lon/Lat boundary requests (vector length = 4), but still somehow uses a Google Maps request to resolve them.

dkahle commented 6 years ago

@emilydinh sorry that it continues to not work for you! The code you posted does work for me, though, and @RomanAbashin as well (apparently). The 403 status you're getting indicates that what ggmap is producing is in fact a well-formed query, Google is just denying the request.

Why? From previous discussions you appear to have enabled the Google Static Maps API for your particular account, so I assume it's not that. And, annoying as it is, it is good that you double checked the key, since that's the most likely problem. I'm assuming that you were successful in the past with that exact key. (Obviously, changing the key in any way will invalidate it.)

Could it be that it does not like your IP for some reason? Perhaps you're behind a VPN that it doesn't like, or in a geographic region that is not supported? (I'm not sure of any of the latter, but that kind of thing is routine...) Otherwise, all I can think of is digging into the documentation.

alis486 commented 6 years ago

Hi I am getting an error, looks like a similar thing to those above and am unsure how to fix:

Error in download.file(url, destfile = tmp, quiet = !messaging, mode = "wb") : cannot open URL 'http://maps.googleapis.com/maps/api/staticmap?center=50.833404,-0.359384&zoom=16&size=640x640&scale=2&maptype=terrain&language=en-EN&sensor=false'

  1. download.file(url, destfile = tmp, quiet = !messaging, mode = "wb")
  2. get_googlemap(center = location, zoom = zoom, maptype = maptype, scale = scale, messaging = messaging, urlonly = urlonly, force = force, filename = filename, color = color, language = language)
  3. get_map(location = c(lon = LonCen, lat = LatCen), zoom = 16, maptype = "terrain")
dkahle commented 6 years ago

@RomanAbashin: If I recall correctly, both of those use Google's geocoding service to figure out where the place is.

@alis486 I think your solution is

if(!requireNamespace("devtools")) install.packages("devtools")
devtools::install_github("dkahle/ggmap", ref = "tidyup")

Then reload R, ggmap, register your API key (see ?register_google), and you should be good to go.

alis486 commented 5 years ago

@alis486 I think your solution is

if(!requireNamespace("devtools")) install.packages("devtools")
devtools::install_github("dkahle/ggmap", ref = "tidyup")

Then reload R, ggmap, register your API key (see ?register_google), and you should be good to go.

So I ran this and worked the first time but now the error is 'r in get_googlemap(center = location, zoom = zoom, maptype = maptype, : Forbidden (HTTP 403).'

emilydinh commented 5 years ago

Hi @dkahle,

Sorry I've been too busy to respond to you sooner. Anyways, I think me having an IP issue is possible but unlikely. I've tried my code on 3 different computers (one at my university, my personal laptop, and my home desktop), but have gotten the same errors again and again.

I'm thinking my issues have to do with the billing as @RomanAbashin mentioned. I'm new to Google Console, so I didn't know I needed billing enabled. Plotting the default map worked for me just once maybe because I'm hitting a request quota and am 403‘d afterwards for the rest of the day (even though I'm not making thousands of requests?).

I've read the documentation, and see that Google Maps Static API can charge me per request? If so, would I essentially be paying to use ggmap? I'm a student, so I'm concerned about this cost.

CCC416 commented 5 years ago

someone,can use in SHINY?

rrmn commented 5 years ago

@emilydinh Check out the pricing sheet. You have 200$ monthly credit if you enable billing, which is equivalent to up to 100,000 map requests. Basically free if you use it only for small-time development.

JanElgner commented 5 years ago

I had simillar problem as @alis486 (Forbidden (HTTP 403) ) and I would like to sum up the problems and how to solve it.

Firstly I created API-key. You need to visit https://console.cloud.google.com and create a new project (write name, create) Next step: navigation menu -> APIs and services -> Library -> Maps Static API (If you visit "Credentials", you can see more details about your Api-key) Next step: You need create a billing acount (I don´t pay anything). You will get 300$ extra credit and about geocoding, remember, 200$ will get you 40,000 free calls per month (I know it from google support)

see Other types of requests related to places -> geocoding: https://cloud.google.com/maps-platform/pricing/sheet/?refresh=1

Secondly, in R studio, you will do exatly what @dkahle wrote and copy your API-key from Credentials of your project.

if(!requireNamespace("devtools")) install.packages("devtools") devtools::install_github("dkahle/ggmap", ref = "tidyup")

register_google(key = "my_google_key_here")

It works for me :), I am from Czech Rep. and I live in Edinburgh at the moment, I tried many computers, IP address hasn´t any influence for me.

dvorw commented 5 years ago

Thanks for such a detailed solution recommendation! However... I still have the same problem wheter using ggplot or RGoogleMaps, even after following all above instructions (up to creating a billing account). Has anybody else still continued with access problems after registering an API key. I need download no more than a few dozen maps per month, and never had the problem before until now.

rrmn commented 5 years ago

I still have the same problem wheter using ggplot or RGoogleMaps, even after following all above instructions (up to creating a billing account).

Same problem, 403 Forbidden? That usually means that you entered an invalid key or did not enable (!) billing for your account (which is a second step after creating a billing account)

In the meantime:

Interim solution without using the Google Maps API:

library(ggmap)
library(tmaptools)
ggmap(get_stamenmap(rbind(as.numeric(paste(geocode_OSM("Vienna")$bbox))), zoom = 11))))

image

dvorw commented 5 years ago

Thanks Roman for proposing this interim solution. It works! if not ideal, while i try to wade through my Google account page

Sent from my iPhone

On 9 Oct 2018, at 13.57, Roman Abashin notifications@github.com wrote:

I still have the same problem wheter using ggplot or RGoogleMaps, even after following all above instructions (up to creating a billing account).

Same problem, 403 Forbidden? That usually means that you entered an invalid key or did not enable (!) billing for your account (which is a second step after creating a billing account)

In the meantime:

Interim solution without using the Google Maps API:

library(ggmap) library(tmaptools) ggmap(get_stamenmap(rbind(as.numeric(paste(geocode_OSM("Vienna")$bbox))), zoom = 11))))

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or mute the thread.

statshermit commented 5 years ago

someone,can use in SHINY?

Yes I use it in Shiny.

ajcanepa commented 5 years ago

I had simillar problem as @alis486 (Forbidden (HTTP 403) ) and I would like to sum up the problems and how to solve it.

Firstly I created API-key. You need to visit https://console.cloud.google.com and create a new project (write name, create) Next step: navigation menu -> APIs and services -> Library -> Maps Static API (If you visit "Credentials", you can see more details about your Api-key) Next step: You need create a billing acount (I don´t pay anything). You will get 300$ extra credit and about geocoding, remember, 200$ will get you 40,000 free calls per month (I know it from google support)

see Other types of requests related to places -> geocoding: https://cloud.google.com/maps-platform/pricing/sheet/?refresh=1

Secondly, in R studio, you will do exatly what @dkahle wrote and copy your API-key from Credentials of your project.

if(!requireNamespace("devtools")) install.packages("devtools") devtools::install_github("dkahle/ggmap", ref = "tidyup")

register_google(key = "my_google_key_here")

It works for me :), I am from Czech Rep. and I live in Edinburgh at the moment, I tried many computers, IP address hasn´t any influence for me.

This solution worked also for me. It's easy to get loose when activating the "billing" account but actually you don't have to pay. Just as a help for non-programming people (like me!), when you are going to register your google using the register_google() function with your "key", firstly you should load the ggmap() library. I know it's really obvious, but just in case!

library(ggmap) register_google(key = "my_google_key_here")

Many Thanks to @JanElgner for the solution and to @dkahle for showing me the way and for the ggmap package!...