Google API key error in ggmap even when specifying other source
Asked Answered
C

1

13

I've started using the package ggmap after a while again, now I'm encountering a problem when I try to fetch a map using the function get_map. No matter which source I specify, I always get the error

Error: Google now requires an API key.
   See ?register_google for details.

although I'm not sure why a call like

get_map(location = "texas", zoom = 6, source = "stamen")

Would need an API call to google. Has anyone experience something similar and is there a known workaround?

Cicerone answered 26/10, 2019 at 18:20 Comment(3)
From the docs for the API key-related ggmap functions (e.g. google_key): "As of mid-2018, the Google Maps Platform requires a registered API key. While this alleviates previous burdens (e.g. query limits), it creates some challenges as well. The most immediate challenge for most R users is that ggmap functions that use Google's services no longer function out of the box, since the user has to setup an account with Google, enable the relevant APIs, and then tell R about the user's setup."Mister
Yes, that's why I tried to circumvent this by using a different source such as stamen or OSM, but even then you get that error, and I don't know why you would need a google api call to get some OSM basemap. That's why this looks like a bug to meCicerone
Under the hood, get_map uses the google geocoding function to get the coordinates of that location, unless you provide the bbox object that get_stamenmaps would expect. Relevant part of the source code: github.com/dkahle/ggmap/blob/…Mister
M
4

As @camille point out, this could be solve providing a bbox object which we can do with the package {osmdata}, function getbb()

In your case it would be:

pacman::p_load(ggmap, osmdata)
get_map(location = getbb("texas"), zoom = 6, source = "stamen")

Conclusion:

No need to create a google API key to retrieve a basemap from google map or openstreet maps. Hope it helps.

Maldonado answered 23/5, 2022 at 18:26 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.