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

时间:2019-07-14 07:42:10

标签: php google-maps

我已经看到this topic提出了针对当前问题的解决方案,尽管由于我使用的是我最近购买的php系统的一部分代码,所以不确定如何实现它如何修改我的代码

这是目前在我的代码上运行的方式

array('file' => '', 'path' => 'https://maps.google.com/maps/api/js?'.$api_key_str.'sensor=false&language=' . $this->option_arr['o_map_language'])

我应该如何应用代码,这样我才能在页面中多次运行google地图?

谢谢!

1 个答案:

答案 0 :(得分:0)

似乎您尝试多次实施地图,并且正在调用Maps Javascript API脚本标记。请注意,Maps Javascript API脚本标记仅应调用一次,并且您可以通过声明多个地图实例化来在站点中添加多个地图,例如:

map = new google.maps.Map(document.getElementById('map'), {
    center: {lat: -34.397, lng: 150.644},
    zoom: 8
  });

这里也是一个示例:

var map;
var map1;
function initMap() {
  map = new google.maps.Map(document.getElementById('map'), {
    center: {lat: -34.397, lng: 150.644},
    zoom: 8
  });
  
  map1 = new google.maps.Map(document.getElementById('map-1'), {
    center: {lat: -34.397, lng: 150.644},
    zoom: 8
  });
}
/* Always set the map height explicitly to define the size of the div
 * element that contains the map. */
#map {
  height: 45%;
}
/* Optional: Makes the sample page fill the window. */
html, body {
  height: 100%;
  margin: 0;
  padding: 0;
}

#map-1 {
  height: 45%;
}
<h3>
Map #1
</h3>
<div id="map"></div>
<h3>
Map #2
</h3>
<div id="map-1"></div>
<!-- Replace the value of the key parameter with your own API key. -->
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyAj0aaMu_aY6xiDSWH0ac_4pqN_l-opwmI&callback=initMap" async defer></script>

希望这会有所帮助。