Cannot get Google Maps API Key to work

Hello guys,

I’m trying to use Geocoding to display the client home address:

results=GoogleMap.geocode(address=self.address)
marker=Marker(position=results[0].geometry.location)
map.add_component(market)

So I’m trying to configure Geocoding < Google Maps < Google Cloud Platform, but cannot get it to work and keep getting the error ExternalError: Google Maps authorization failed - is the API key invalid?

I have set up Google Cloud Platform (at the moment use the free $200/month), enable Geocoding API, generate an API key, restrict it to my bazari.anvil.app and to geocoding API, and copy paste the same Maps API key to Anvil’s Google API. What do I do wrong?

After reading more carefully the doc, now I’m wondering the Anvil’s API key text box refer to a Google API Key or a Google OAuth client ID?

Hi @thai,

Here’s the guide for obtaining an API key for your app: Maps JavaScript API Guide

You’ll need an API key for the Maps JavaScript API, which looks like this in the GCP Console:

Screenshot 2020-08-11 at 09.47.49

Hi @bridget. I’ve already done that, and I copied exactly the newly created API Key (without any API Key Restriction) but it still didn’t work. What else can I try?

Still cannot get it to work despite having tried very carefully several times now. Someone that has used Geocoding API with Anvil please help!

@thai it looks like you have the Geocoding API and Geolocation API enabled, but not the Maps JavaScript API.

Please try obtaining an API key for the Maps JavaScript API - I think that should do the trick!

Thanks @bridget. Works flawlessly. By the way, I realized that the doc of the Google Map component might have a typo. In the example of the Geocoding, the doc writes:

m = Marker(position=results[0].geometry.location)

instead of

m = GoogleMap.Marker(position=results[0].geometry.location)