Forum
Google Maps API Key problem
I have updated two local sites from 2.8.29 to 2.8.31 and added a Google Maps API Key. But my pages give me a Google Maps API error: InvalidKeyMapError
in console and of course the map doesn't load. To get this to work, I need to resave all regions that have a map field type. Is that expected behaviour?
On some sites, it won't be practical to resave all regions (there are 50 properties and maps on one site for example).
I tried republishing pages but only saving a region individually will load the map correctly.
Is there a better way of doing this and getting the maps to load without saving regions individually?
PS: The local site address is listed as a referrer in Google Developer Console credentials for the API Key.
The HTML is cached, so it won't be regenerated until you save the region.
This was a change with the Maps API, so it's not something I can really do anything about unfortunately.
OK, thanks.
I imagined that republishing would resave regions but I will have to resave individually if that's not the case.
Just been doing a rough count of regions I need to save. I have 10-11 sites with approx 250 properties in total (each with a map region). This will take a while. Is there anything else I can do?
Do they need updating?
Strictly speaking, no. I was just trying to keep within a few versions so as not to fall too far behind.
I have had one thought though. If I was to make a small inconsequential change to the region template HTML, would republishing save all regions? Effectively cache busting. Or have I misunderstood how this works?
Republishing with the key in place should do it. What output are you seeing? Is the key there?
Republishing with key in place does not create Google maps URL with key value. Saving a region changes the maps URL to
//maps.google.com/api/staticmap?key=keyvalue...
Only the static map or in the JavaScript block too?
JS block contains
CMSMap.key='keyvalue'
after region is saved .... but key not present in this or static map after republishing.Looking at it again, the republish command doesn't reperform the API lookups. If it did the rush of requests might see you being throttled by whichever API is concerned.
I don't think that sees us any further forward though.
Ah OK. If you think of another option, let me know. But I will likely only update the sites when I have to .... and when have time to resave all regions. Dull job but looks like the only choice atm.
Unfortunately these things sometimes happen when you have a dependancy on third party APIs. It's why Perch tries to keep so much in-house.