Google Maps v3 Object为null或未定义

时间:2011-12-12 15:26:11

标签: google-maps

我得到“无法获取属性'3'的值:对象为null或未定义”在IE7和IE8中的这行代码中,并且不知道如何解决它。非常感谢任何帮助。

marker = new google.maps.Marker

我不确定undefined是什么意思,因为我在前面的代码块中声明了变量。任何帮助都非常感谢... http://jsfiddle.net/svuce/1/

function initialize() {
    var markers = new Array();
    var locations = [
      ['Donegal', 'Some text goes here<br />text', 'walking', -33.900542, 151.174856],
      ['Bondi Beach', 'Some text goes here<br />text', 'walking', -33.890542, 151.274856],
      ['Coogee Beach', 'Some text goes here<br />text', 'golfing', -33.923036, 151.259052],
      ['Cronulla Beach', 'Some text goes here<br />text', 'family', -34.028249, 151.157507],
      ['Manly Beach', 'Some text goes here<br />text', 'explore', -33.80010128657071, 151.28747820854187],
      ['Maroubra Beach', 'Some text goes here<br />text', 'cycling', -33.950198, 151.259302],
    ];


    var map = new google.maps.Map(document.getElementById('map-canvas'), {
      zoom: 10,
      center: new google.maps.LatLng(-33.92, 151.25),
      mapTypeId: google.maps.MapTypeId.ROADMAP
    });

    var infowindow = new google.maps.InfoWindow();
    var marker, i;

    for (i = 0; i < locations.length; i++) {  
        marker = new google.maps.Marker({
            position: new google.maps.LatLng(locations[i][3], locations[i][4]),
            map: map,
            icon: 'images/map_'+locations[i][2]+'_image.png'
        });

        markers.push(marker);

        var boxText = document.createElement("div");

      google.maps.event.addListener(marker, 'click', (function(marker, i) {
        return function() {
            boxText.style.cssText = "border: none 0; margin-top: 8px; background:#fff; padding: 8px;border:1px solid #877856;";
            boxText.innerHTML = locations[i][0]+"<br />"+locations[i][2]+"<br />"+locations[i][1]+"<img src='images/tipbox.png' class='infobox-arrow' />";

            $(".infobox-close").remove();

            var myOptions = {
                     content: boxText
                    ,disableAutoPan: false
                    ,maxWidth: 0
                    ,pixelOffset: new google.maps.Size(-140, -180)
                    ,zIndex: null
                    ,boxStyle: { 
                      opacity: 1
                      ,width: "280px"
                     }
                    ,closeBoxMargin: "12px 7px 0 0"
                    ,closeBoxURL: "http://www.google.com/intl/en_us/mapfiles/close.gif"
                    ,infoBoxClearance: new google.maps.Size(1, 1)
                    ,isHidden: false
                    ,pane: "floatPane"
                    ,enableEventPropagation: false
            };
            var ib = new InfoBox(myOptions);
          ib.open(map, marker);
        }
      })(marker, i));
    }

    // == shows all markers of a particular category, and ensures the checkbox is checked ==
      function show(category) {
        for (var i=0; i<locations.length; i++) {
          if (locations[i][2] == category) {
            markers[i].setVisible(true);
          }
        }
      }

      // == hides all markers of a particular category, and ensures the checkbox is cleared ==
      function hide(category) {
        for (var i=0; i<locations.length; i++) {
          if (locations[i][2] == category) {
            markers[i].setVisible(false);
          }
        }
      }

      // == show or hide the categories initially ==
        show("walking");
        hide("golfing");
        hide("family");
        hide("explore");
        hide("cycling");



        $("#activities .checkbox").click(function(){
            var cat = $(this).attr("value");

            // If checked
            if ($(this).is(":checked"))
            {
                show(cat);
            }
            else
            {
                hide(cat);
            }
        });
  };

  window.load = initialize();

1 个答案:

答案 0 :(得分:1)

删除数组最后一部分末尾的逗号,这会导致IE中的错误:

  ['Maroubra Beach', 'Some text goes here<br />text', 'cycling', -33.950198, 151.259302],