繁体   English   中英

您在此页面上多次包含 Google Maps API。 这可能会导致意外错误(wordpress)

[英]you have included the Google Maps API multiple times on this page. This may cause unexpected errors (wordpress)

使用 google map api 时,我的控制台出现两个错误:

1-未捕获的引用错误:未定义初始化

2-您在此页面上多次包含 Google Maps API。 这可能会导致意外错误有什么帮助吗?

JS

<script type="text/javascript">

function initialize() {


 var myLatLng = {lat: 42.52501, lng: 2.938979}; 
     var map = new google.maps.Map(document.getElementById('map'), {
    zoom: 12,
    center: myLatLng,
    scrollwheel: false,
    draggable:true,



  });
     var image='logo.png';
     var marker = new google.maps.Marker({
    position: myLatLng,
    map: map,
    icon:image

  });


}

</script>

头文件

 <script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?key='YOUR API KEY HERE'"></script>

<script src='https://maps.googleapis.com/maps/api/js?v=3.exp'></script>

<body  onload="initialize()";></body>

这实际上是一个例子。 如果结果是答案,那么您可以将其标记为这样 - 但这确实是一个例子。 您可以从 jQuery 网站了解如何加载 jQuery,Google 还提供了一种通过 Google 加载 jQuery 的方法。

笔记:我刚刚意识到同时拥有这两个是矫枉过正的。 您可能只需要 ready() 函数。

<html>
<head>
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?key=PUT YOUR API KEY HERE"></script>

<!--script src='https://maps.googleapis.com/maps/api/js?v=3.exp'></script-->
<script src="http://localhost/test_7/jquery-1.11.3.min.js"></script>

<script type="text/javascript">

$(document).ready(function()
{
function initialize() {

 var myLatLng = {lat: 42.52501, lng: 2.938979};
     var map = new google.maps.Map(document.getElementById('map'), {
    zoom: 12,
    center: myLatLng,
    scrollwheel: false,
    draggable:true,

  });
     var image='logo.png';
     var marker = new google.maps.Marker({
    position: myLatLng,
    map: map,
    icon:image

  });

}

    initialize();
});

</script>

</head>
<body>
test
</body>
</html>

此外,它只是

window.onload()

而不是 $(window).onload()。 对于那个很抱歉! :-)

只需更换

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.js"></script>


只需更换

<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?v=3.exp&libraries=places&key="></script>

<script type="text/javascript" src="//https:maps.google.com/maps/api/js?libraries=places&key="></script>

记得添加你的 google api 密钥


暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM