Forum

Thread tagged as: Question, Field-Types

google Maps API Key

Hi

I'm getting a Google Maps API error: MissingKeyMapError in the back end of perch when using the Perch Map field, so I wondered what would be best practice when loading the maps script from Google with my API key, so that Perch is requesting it correctly? Hopefully wanted to avoid editing perch core on this back end issue.

Thanks

Adam Menczykowski

Adam Menczykowski 1 points

  • 5 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

I don't think you should need an API key. Are you up to date?

Yeah. 2.8.29

I am using my own JS file for maps for the front end, which was taken from an older project. However my front end works fine, its in Perch I'm having the problem.

Drew McLellan

Drew McLellan 2638 points
Perch Support

So the maps JavaScript used by the field type is stock?

Yeah. I double checked that by replacing perch core. Presumably that is a good test? I do define map JS in config to my own file. Would that affect the back end?

Drew McLellan

Drew McLellan 2638 points
Perch Support

It shouldn't do, no.

Where are you getting the error? In the browser console?

Yes its in the Browser JS console.

?id=1:36 GET https://maps.google.com/maps/api/staticmap?center=53.4839456,-2.234009&size=…0x400&zoom=15&maptype=map&markers=color:red|color:red|53.4839456,-2.234009 403 (Forbidden)

js:32 Google Maps API error: MissingKeyMapError https://developers.google.com/maps/documentation/javascript/error-messages#missing-key-map-error

util.js:211 Google Maps API warning: NoApiKeys https://developers.google.com/maps/documentation/javascript/error-messages#no-api-keys
Drew McLellan

Drew McLellan 2638 points
Perch Support

Could it be that your IP address has exhausted its API allowance for the day?

Hmm... tried connecting through my phone, checked the IP and yes its different from my broadband connection, however the same JS error persists.

Drew McLellan

Drew McLellan 2638 points
Perch Support

Ok. I'll see if I can reproduce it.

Hi, any news on this?

I got the same error after changing from development domain to production domain.

Worked just fine on the dev-domain:

js:32 Google Maps API error: MissingKeyMapError https://developers.google.com/maps/documentation/javascript/error-messages#missing-key-map-error

Google Maps API warning: NoApiKeys https://developers.google.com/maps/documentation/javascript/error-messages#no-api-keys

I am happy to use an API key, it would be good to simply get your advice on how best to implement with the Maps fieldtype... Perhaps as this is happening with other people, there could be something in the config.php that you reference?

Thanks

Drew McLellan

Drew McLellan 2638 points
Perch Support

Can you confirm that you're just getting a warning and nothing is actually failing?

I am just getting a warning now Drew. Maps load successfully on the front end and back end.

Google Maps API warning: NoApiKeys https://developers.google.com/maps/documentation/javascript/error-messages#no-api-keys

It was the case last week that maps wouldn't load in the back end, possibly as you suggested due to useage - however I only would have loaded that map 30-50 times that day when working on the site, so would appreciate an option in the future to be able to load a maps API key in case this reoccurs.

Thanks

Drew McLellan

Drew McLellan 2638 points
Perch Support

Yes, clearly, I'm simply trying to understand the issue you're seeing. The Google Maps API has changed in this regard, but I'm having a hard time establishing when why and how.

Drew McLellan

Drew McLellan 2638 points
Perch Support

It looks like the requirements may have changed in January, but the console warnings were a new addition a couple of weeks ago.

Ok thanks, yes I've noticed on some other non Perch sites that this has been happening.

Drew McLellan

Drew McLellan 2638 points
Perch Support

There's a new option going into 2.8.30 to enable you to add an API key.

OK Thank you Drew

Hi,

Is there something I can do in the short term to fix this in the Perch back end? Now I have an overlay over my Maps field so cannot add new Map field data

Drew McLellan

Drew McLellan 2638 points
Perch Support

What do you mean by an overlay?