繁体   English   中英

您已在此页面上多次包含Google Maps API

[英]You have included the Google Maps API multiple times on this page

我正在使用Google Map API v3。 我正在使用wpestate房地产wordpress主题。 这是我在模板文件中的代码。

<script src="https://maps.googleapis.com/maps/api/js?v=3.exp"></script>
<script src="https://maps.googleapis.com/maps/api/js?   
  v=3.exp&sensor=false&libraries=places"></script>
  <script>
var geocoder;
var map;
function initialize() {

var input = document.getElementById('address');
var options = {

componentRestrictions: {country: "in"}
};
var autocomplete = new google.maps.places.Autocomplete(input,options);
geocoder = new google.maps.Geocoder();


//var latlng = new google.maps.LatLng(18.52043030000, 73.85674369999);

var mapOptions = {
 zoom: 15,
//center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP,

}

var map = new google.maps.Map(document.getElementById('googleMap'), mapOptions);

}



function codeAddress() {
 var address = document.getElementById('address').value;


 geocoder.geocode( { 'address': address}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {

 map.setCenter(results[0].geometry.location);
  var marker = new google.maps.Marker({
      map: map,
      position: results[0].geometry.location
  });
  } else {
  alert('Geocode was not successful for the following reason: ' + status);
  }
 });
}


 google.maps.event.addDomListener(window, 'load', initialize);
 </script>

它按预期运行,但在控制台中显示错误“您已在此页面上多次包含Google Maps API。这可能会导致意外错误。”。 因此,该地图不会在地图上显示属性。

删除第一行:

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

您两次包含Google Maps API。

您的问题是,就像其他人发现的一样,Google地图的脚本重复了。 请检查下面的链接以获取工作代码。

http://jsbin.com/husahasu/1/edit

要渲染地图, 您需要指定其中心 没有它就不会渲染。 您还需要为元素添加css。 将其放在文档的开头。

<style type="text/css">
 html { height: 100% }
 body { height: 100%; margin: 0; padding: 0 }
 #googleMap { height: 100% }
</style>

就我而言,我在首页和div之前两次插入了到库的链接。 我删除了任何链接,它将正常工作。 您检查页面中的链接。

暂无
暂无

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

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