2011-12-12 82 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],