加载Google地图的问题 - SensorNotRequired [英] Issue on Loading Google Map - SensorNotRequired
问题描述
我试图在WordPress网站上运行Google地图。代码在这个 JSFIDDLE 上运行完美,但是当我把它带到WordPress时,我得到这个错误
Google Maps API警告:SensorNotRequired:
https://developers.google.com/maps/documentation/javascript/error-messages
我也试过这段代码
< script language =javascriptsrc =https: //maps.googleapis.com/maps/api/js?sensor=true&v=3\"></script>
但结果相同。
最后,我尝试从API获取密钥并使用它。
< script src =https://maps.googleapis。 com / maps / api / js?key = xxxxxxxxxxxxxxxxxxxxxxxxxxx& callback = initMap
async defer>< / script>
现在我收到了这个错误
未捕获的TypeError:window.initMap不是一个函数
请让我知道为什么这是发生和我如何解决它?
不是:
< script language =javascriptsrc =https://maps.googleapis.com/maps/api/js?sensor=true&v=3>< / script>
试试:
< script language =javascriptsrc =https://maps.googleapis.com/maps/api/js?v=3>< / script>
传感器参数不再需要Google地图
JavaScript API。它不会阻止
的Google Maps JavaScript API正常运行,但我们建议您从脚本元素中移除传感器
参数。
I am trying to run Google Map on a WordPress site. The code is running perfectly on this JSFIDDLE but when I take it to WordPress I am getting this error
Google Maps API warning: SensorNotRequired: https://developers.google.com/maps/documentation/javascript/error-messages
I also tried this code
<script language="javascript" src="https://maps.googleapis.com/maps/api/js?sensor=true&v=3"></script>
but the result is same.
Finally I tried to get a key from API and use it
<script src="https://maps.googleapis.com/maps/api/js?key=xxxxxxxxxxxxxxxxxxxxxxxxxxx&callback=initMap"
async defer></script>
and now I am getting this error
Uncaught TypeError: window.initMap is not a function
can you please let me know why this is happening and how I can fix it?
Instead of:
<script language="javascript" src="https://maps.googleapis.com/maps/api/js?sensor=true&v=3"></script>
Try:
<script language="javascript" src="https://maps.googleapis.com/maps/api/js?v=3"></script>
From the Google Maps API documentation:
The sensor parameter is no longer required for the Google Maps JavaScript API. It won't prevent the Google Maps JavaScript API from working correctly, but we recommend that you remove the sensor parameter from the script element.
这篇关于加载Google地图的问题 - SensorNotRequired的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!