Javascript “您在此页面上多次包含 Google Maps API”错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/44969698/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 02:49:41  来源:igfitidea点击:

"You have included the Google Maps API multiple times on this page" Error

javascripthtmlgoogle-mapsgoogle-maps-api-3

提问by MRDJR97

I have the following in my html page:

我的 html 页面中有以下内容:

    <script type="text/javascript"
            src="http://maps.googleapis.com/maps/api/js?libraries=geometry&sensor=false">
    </script>
    <script 
        async defer
        src="https://maps.googleapis.com/maps/api/js?key=hUnDAdjYG_Wz7u2qL6unHqfBOmvaZ0H1Mg&callback=initMap">
    </script>

First link is for Google's API Geometry Library , and the second initialises and draws the map.

第一个链接用于 Google 的 API Geometry Library ,第二个链接初始化并绘制地图。

I'm getting the error "You have included the Google Maps API multiple times on this page. This may cause unexpected errors."

我收到错误消息“您在此页面上多次包含 Google Maps API。这可能会导致意外错误。”

I know that this can be fixed by calling just one script, and changing the parameters, see Fixing "You have included the Google Maps API multiple times on this page. This may cause unexpected errors."I don't know how to replicate the answer for my problem though.

我知道这可以通过只调用一个脚本并更改参数来解决,请参阅修复“您在此页面上多次包含 Google Maps API。这可能会导致意外错误。” 我不知道如何复制我的问题的答案。

回答by dhaliman

You can include one link:

您可以包含一个链接:

<script type="text/javascript"
        src="http://maps.googleapis.com/maps/api/js?libraries=geometry&sensor=false&key=AIzaSyBSsKUzYG_Wz7u2qL6unHqfBOmvaZ0H1Mg&callback=initMap">
</script>

Basically merging the url parameters in both the links.

基本上合并两个链接中的 url 参数。