1

This past summer I was working on a code in R where I used the packages mapview and ggmap. During the summer the code was working fine. This past week I ran the code without any changes and I get the following message when I use mapview:

mapview(as(tr10, "Spatial"), zcol = "utc_timestamp", lwd = 5,
      legend = TRUE)
Error in htmlwidgets::sizingPolicy(defaultWidth = defaultWidth, defaultHeight = defaultHeight,  : 
unused argument (browser.external = FALSE)

I did not made any changes to my code and I upgrade the package just in case but still does not work. And with ggmap I get the following:

puerto_rico <- get_map(location = c(lon = mean(long), lat = mean(lat)), 
                     maptype = "terrain", source = "google",
                     zoom = 12)
Error in download.file(url, destfile = tmp, quiet = !messaging, mode = "wb") : 
cannot open URL 'http://maps.googleapis.com/maps/api/staticmap?center=18.2,-67.1&zoom=12&size=640x640&scale=2&maptype=terrain&language=en-EN&sensor=false'
In addition: Warning message:
In download.file(url, destfile = tmp, quiet = !messaging, mode = "wb") :

cannot open URL 'http://maps.googleapis.com/maps/api/staticmap?center=18.2,-67.1&zoom=12&size=640x640&scale=2&maptype=terrain&language=en-EN&sensor=false': HTTP status was '403 Forbidden'

Can someone explain what is happening with these packages and what other alternatives do I have for me to access the use of maps for my plots?

Bear
  • 662
  • 1
  • 5
  • 20
  • Disclaimer: mapview developer here. What is your `htmlwidgets` version? This option [was only implemented in April](https://github.com/ramnathv/htmlwidgets/commit/99d6cde69c2a13a68d5dc960c3a38ff1300e8bb2) but is on CRAN now. So updating `htmlwidgets` should solve your problem. – TimSalabim Oct 11 '18 at 16:52
  • I often get the same error due to the firewall at my work – Shinobi_Atobe Oct 16 '18 at 08:53
  • I will check the update of the `htmlwidgets` Thanks! – A. Quinones Oct 16 '18 at 13:47
  • I have the version 1.0 of `htmlwidgets`. I click to update but it's still says version 1.0 and I keep getting the same message when I run `mapview`. I'm going to check what is the version that I need and maybe unistall it and install it again to get the latest version. Thank you so much for commenting here. This is very helpful. – A. Quinones Oct 16 '18 at 14:41
  • I updated the `htmlwidgets` package to the 1.3 version and `mapview` works now. Thank you so much! – A. Quinones Oct 29 '18 at 17:52
  • also: https://stackoverflow.com/q/51481913/5977215 – SymbolixAU Dec 08 '18 at 20:02

1 Answers1

6

Google has tightened controls on API access to Google Map products. This means that you now need a Google API key to use ggmap().

There are a few steps involved:

  1. Visit https://console.cloud.google.com and create a new project.
  2. Set up an API key: navigation menu -> APIs and services -> Library -> Maps Static API
  3. Create a billing account and enable billing for the API key. You will need to provide credit card details but don't need to pay anything. It is a good idea to set some limits on how the API key can be used to prevent theft -- if you are not sharing your code, the easiest way is probably to limit it to requests from your own IP address.
  4. Enable static maps for this api key.
  5. In R, run register_google("<your API key>"). You will need to run this for every new session in which you will use ggmap(). I have added it to my .Rprofile.

Good luck!

Barbara
  • 188
  • 1
  • 8