ACF Google map sometimes not loading properly, throws "Uncaught ReferenceError: google is not defined"

ACF Google map sometimes not loading properly, throws "Uncaught ReferenceError: google is not defined"

我在我的 WordPress 网站上将 ACF 用于 google 地图。有时它工作正常,但大多数情况下地图在页面加载后不呈现并且控制台抛出以下错误:

Uncaught ReferenceError: google is not defined
    at initMap ((index):616)
    at HTMLDivElement.<anonymous> ((index):1178)
    at Function.each (jquery.min.js?ver=3.6.0:2)
    at s.fn.init.each (jquery.min.js?ver=3.6.0:2)
    at HTMLDocument.<anonymous> ((index):1176)
    at e (jquery.min.js?ver=3.6.0:2)
    at t (jquery.min.js?ver=3.6.0:2)

看来您需要添加地图键。

<script src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY"></script>

如果存在,请确保它在 header.

如果有人遇到同样的问题,当我将 document.ready 更改为 window.load 时它对我有用。在官方 ACF 文档中,其 document.ready