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>

location.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 に答える