谷歌地图API停止在Wordpress模板中工作


Google Maps API stopped working in Wordpress Template

所以我的Google Maps API正在工作,但现在不工作了。浏览谷歌API地图上的文档,我没有发现任何变化。我们使用的是Wordpress PHP模板中嵌入的地图,我检查的所有内容似乎都是正确的。有什么变化吗?

这是初始代码:

<section id="main">
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?key=AIzaSyBqnue6HpFD-HQvnk_cOKTQmqAzE6Xb9NQ"></script>
<script type="text/javascript" src="http://www.americanraceronline.com/wp-content/uploads/dev/markerwithlabel.js"></script>
<script type="application/javascript" >
  var map;
  var infoWindow;
  function initialize() {
  var myLatLng = new google.maps.LatLng(40.6,-95.665);
  var myOptions = {
     center: myLatLng,
      scrollwheel: true,
   navigationControl: false,
   mapTypeControl: false,
   scaleControl: true,
   draggable: true,
    disableDefaultUI: true,
     mapTypeId: google.maps.MapTypeId.Whitewater,
                      styles:[/lots of styles here/]};
var poly;
map = new google.maps.Map(document.getElementById("map_canvas"),
myOptions);
var marker1 = new MarkerWithLabel({
   position: new google.maps.LatLng(40.27488643704891, -110.740234375),
   draggable: false,
   raiseOnDrag: false,
   map: map,
   labelContent: "WEST",
   labelAnchor: new google.maps.Point(22, 2),
   labelClass: "mylabels", // the CSS class for the label
   labelStyle: {opacity: 1.0},
    icon: {}
 });

该页面的链接为:http://www.americanraceronline.com/distributors/

我错过了什么?

在浏览器控制台中:

您已多次在此页面上包含Google Maps API。这可能会导致意外错误。main.js:60yl

这不需要太多解释:您必须重复包含Google API,检查您的包含是否只包含API引用一次。

也许是文件main.js,行:60

对于谷歌地图地图选项,需要zoom(请参阅参考资料),例如

var myOptions = {
   center: myLatLng,
   scrollwheel: true,
   navigationControl: false,
   mapTypeControl: false,
   scaleControl: true,
   draggable: true,
   disableDefaultUI: true,
   zoom: 9,
   styles:[/lots of styles here/]
};

例如,我为您的代码创建了一个简单的Fiddle,直到提供了缩放功能才开始工作。