Google Maps API已停止在Wordpress模板中运行

时间:2015-03-05 15:32:53

标签: javascript php wordpress google-maps

所以我的Google Maps API工作正常,现在却不行。查看Google Maps 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/

我错过了什么?

2 个答案:

答案 0 :(得分:0)

在浏览器控制台中:

  

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

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

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

答案 1 :(得分:0)

对于Google Maps mapOptions,需要zoom(请参阅reference),例如

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

例如,我创建了一个简单的Fiddle代码,直到提供缩放才能生效。