2011-05-30 194 views
1

我想讓標記管理器在谷歌地圖V3上工作。我試圖複製教程頁面here上顯示的內容,但似乎無法使其工作。這是我使用至今代碼:谷歌地圖V3標記管理器

function gmapInit() 
    { 
     drawMap(); 
    } 

    function drawMap() 
    { 
     var center = new google.maps.LatLng(..., ...); 
     var mapOptions = { 
      center: center, 
      scrollwheel: false, 
      mapTypeId: google.maps.MapTypeId.ROADMAP, 
      disableDefaultUI: true, 
      zoomControl: true, 
      streetViewControl: true 
     }; 
     var map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions); 


     var mgr = new MarkerManager(map);. 
     google.maps.event.addListener(mgr, 'loaded', function() 
     { 
      createMarkers(map, mgr); 
     }); 

     map.setCenter(center); 
    } 

    function createMarkers(map, mgr) 
    { 
     var bounds = new google.maps.LatLngBounds(); 

    <c:forEach var="place" items="${places}"> 
     var point = new google.maps.LatLng(..., ...);  
     bounds.extend(point);  

     var image = new google.maps.MarkerImage("...",    
       new google.maps.Size(25, 25), 
       new google.maps.Point(0, 0), 
       new google.maps.Point(0, 25), 
       new google.maps.Size(25, 25)); 

     var marker = new google.maps.Marker({ 
      position: point, 
      map: map, 
      icon: image 
     }); 

     google.maps.event.addListener(marker, 'click', function() 
     { 
      ... 
     });   

     mgr.addMarker(marker, 20); 

    </c:forEach> 
     map.fitBounds(bounds); 
     mgr.refresh(); 
     var listener = google.maps.event.addListener(map, "idle", function() 
     { 
      if (map.getZoom() > 16) 
      { 
       map.setZoom(16); 
      } 
     }); 
    } 

然而,圖標仍然繼續得到顯示,無論我提出什麼樣的價值我放大它,什麼縮放級別另外,我不斷收到以下錯誤:

grid is undefined 

對此有何見解表示讚賞:)

我使用的MarkerManager文件可以發現here

+0

這是實際的代碼嗎?我看到一個小錯誤「var mgr = new MarkerManager(map);.」如果你能提供一個jsfiddle例子,我們可以更容易地檢查這個案例 – 2011-05-31 06:55:52

回答

2

這似乎已經解決問題:

var listener = google.maps.event.addListener(map, "idle", function() 
     { 
      if (map.getZoom() > 16) 
      { 
       map.setZoom(16); 
      } 
      mgr.refresh(); 
     }); 

問題是地圖沒有指定縮放級別。

1
var marker = new google.maps.Marker({ 
     position: point, 
     map: map, 
     icon: image 
    }); 

    google.maps.event.addListener(marker, 'click', function() 
    { 
     ... 
    });   

    mgr.addMarker(marker, 20); 

    you should not assign map to marker while you are adding it to MarkerManager. 

    var marker = new google.maps.Marker({ 
     position: point, 
     **// map: map,** 
     icon: image 
    }); 

    google.maps.event.addListener(marker, 'click', function() 
    { 
     ... 
    });   

    mgr.addMarker(marker, 20);