1

我对 Internet Explorer 8 引发的一些错误感到有些困惑,但 Firefox 却没有。

我看到以下错误:

Webpage error details

User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windwos NT 5.1; Trident/4.0; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)
Timestamp: Wed, 13 Jun 2012 08:33:22 UTC

Message: Object expected
Line: 3
Char: 1
Code: 0
URI: http://<ipAddress>/.../locations.js

Message: Syntax error
Line: 34
Char: 11
Code: 0
URI: http://<ipAddress>/.../testMap1.html

我正在使用以下文件...

testMap1.html:

    <div id="map_canvas" style="width: 1200px; height: 700px;">map div foo</div>
    <script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?sensor=false"></script>
    <script type="text/javascript" src="/static/app/foo/locations.js"></script>
    <!--<script type="text/javascript" src="/static/app/foo/script.js"></script>-->
    <script type="text/javascript">

  var centerPoint = new google.maps.LatLng(9.449062,7.950439);

  var parliament = new google.maps.LatLng(9.449062,7.950439);
  var parliament1 = new google.maps.LatLng(34.449062,7.950439);
  var marker;
  var map;
  var i;

  function initialize() {
      var mapOptions = {
        zoom: 2,
        mapTypeId: google.maps.MapTypeId.HYBRID,
        center: centerPoint
      };

      map = new google.maps.Map(document.getElementById("map_canvas"),
              mapOptions);


      for (i = 0; i < locations.length; i++) {
          marker = new google.maps.Marker({
            map:map,
            draggable: false,
            animation: google.maps.Animation.DROP,
            position: new google.maps.LatLng(locations[i][0], locations[i][1]),
          });
          google.maps.event.addListener(marker, 'click', toggleBounce);
      }
  }

// for toggleBounce, need to add ", toggleBounce" back into previous brackets.

  function toggleBounce() {

      if (marker.getAnimation() != null) {
        marker.setAnimation(null);
      } else {
      marker.setAnimation(google.maps.Animation.BOUNCE);
      }

  }
    </script>

位置.js:

  var locations = [
     [9.449062, 7.950439, 0],
     [34.449062, 10.950439, 50]
  ];

关于为什么这不起作用的任何想法?任何致盲错误?

问候,

马特

4

2 回答 2

4

从此行中删除尾随逗号:

position: new google.maps.LatLng(locations[i][0], locations[i][1]),

它会导致 IE 出现问题。

marker = new google.maps.Marker({
   map:map,
   draggable: false,
   animation: google.maps.Animation.DROP,
   position: new google.maps.LatLng(locations[i][0], locations[i][1]) //removed comma
});
于 2012-06-13T09:05:49.737 回答
1

ioseb 已经发布了完美的答案。但是,为了防止将来出现此类错误,我建议使用 google 闭包编译器,如果发生此类错误,它将警告您。你在这里:http ://code.google.com/p/closure-compiler/downloads/list

于 2012-06-13T10:17:59.703 回答