doublesecretagency / craft-googlemaps

Google Maps plugin for Craft CMS - Maps in minutes. Powered by the Google Maps API.
https://plugins.doublesecretagency.com/google-maps/
Other
10 stars 8 forks source link

Address field fails to initialize – NotLoadingAPIFromGoogleMapsError #92

Closed MoritzLost closed 9 months ago

MoritzLost commented 11 months ago

We're seeing an issue where the address field sometimes fails to intialize:

Screenshot 2023-07-17 at 11 06 21

The console shows the following error:

Screenshot 2023-07-17 at 11 06 33

Google Maps JavaScript API error: NotLoadingAPIFromGoogleMapsError https://developers.google.com/maps/documentation/javascript/error-messages#not-loading-api-from-google-maps-error

This only happens with editors that have been using the CMS for a while. Reloading the page normally does not make the error go away. However, doing a full reload (CMD + SHIFT + R) does fix the issue for that entry, though not for others. So this is somehow related to browser caching.

The error message is curious, it indicates that the Google Maps JS library was loaded from the wrong URL, but the plugin is not doing that. I found two thread on Stack Overflow that indicate this error can be related to an expired token that the browser may have cached:

Could a fix similar to the suggested solution there be implemented in the plugin? We've told the editors to to a full reload when this error occurs, but of course that's not ideal.

lindseydiloreto commented 11 months ago

Very interesting, thanks for reporting. Have you double-checked that your API keys are 100% valid?

https://plugins.doublesecretagency.com/google-maps/guides/test-google-api-keys/

MoritzLost commented 11 months ago

@lindseydiloreto Yes, our API keys are completely valid and work normally except for this bug. When this issue doesn't occur, the address field and the map initialize normally and the autocomplete works correctly. And doing a full reload fixes the issue for that particular entry, so it's definitely related to the issues I linked, not to the API keys.

We've also never changed the API keys on that site, so it can't be something like the browser caching old API keys.

lindseydiloreto commented 9 months ago

We've just released v4.3.6, which includes a cache-busting string on the Google Maps API URL.

It generates a new cache token every 12 hours, which aligns with this description of the problem and solution. Hopefully that does the trick! 🤞

Thanks again for reporting it! If you wouldn't mind, keep an eye on the problem over the next few weeks or months to be sure that our solution is working.

MoritzLost commented 9 months ago

@lindseydiloreto Looks great, thanks!

We've updated to the new version and let the client know that the issue should be fixed now. I'll report back in case the problem still persists.