2011-12-12 141 views
0

我收到“无法获取属性的值'3':对象为空或未定义”在IE7和IE8的这行代码中,并且不知道如何解决它。任何帮助不胜感激。谷歌地图v3对象为空或未定义

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(); 
+0

这条线如何:var infowindow = new google.maps.InfoWindow(); - 那样有用吗? –

+0

错误可能来自您正在标记构造函数中的其中一个参数 - 现在尝试对它们进行硬编码 –

回答

1

获取你的数组的最后一个部分的结尾去掉后面的逗号,这会在IE中导致错误:

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