首页 > 解决方案 > ACF Google 地图有时无法正确加载,抛出“Uncaught ReferenceError: google is not defined”

问题描述

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

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)

谷歌未定义错误

标签: wordpressgoogle-mapsgoogle-maps-api-3advanced-custom-fields

解决方案


看起来您需要添加地图键。

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

如果它存在,请确保它在标题中。


推荐阅读