我遇到了一些麻烦,应该很容易,但我遗漏了一些但不确定是什么。我将代码放在两个单独的js文件中,然后在头部调用它们。
这是两张地图。
http://www.mesquiteweather.net/gmap/aqiCurrent.js
http://www.mesquiteweather.net/gmap/aqiForecast.js
然后我会在头部添加它。这适用于一页上的单个地图,但不适用于两个。
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyAmOjwJpRcp48pn7smsrprlnN90iYBxR8g&sensor=false"></script>
<script type="text/javascript" src="gmap/aqiCurrent.js"></script>
<script type="text/javascript" src="gmap/aqiForecast.js"></script>
</head>
<body onload="initialize()">
然后我像这样调用html中的地图。
<div id="aqiCurrent" style="width:100%; height:400px"> </div>
<div id="aqiForecast" style="width:100%; height:400px"> </div>
它只显示第二张地图而不是第一张地图。如果我从头部删除其中一个呼叫,则第一个显示。所以我知道代码很好,因为我可以让一个或另一个加载和显示。我只是无法同时加载和显示它们。我不确定我错过了什么。
-Thanks
答案 0 :(得分:1)
Multiple Google Maps won't display on single page
可能重复在两个javascript文件中都有一个具有相同名称的函数(“initialize”)。
那不行。