2011-08-15 26 views
0

我有一個函數來幾個標記加載到地圖(Maps API第3):提高性能裝載幾個標記與地圖V3

function displayPois(){ 
    // Delete all POI marker from map 
    if(poiMarker.length > 0){ 
     for (var i = 0; i < poiMarker.length; i++) { 
       poiMarker[i].setMap(null);  
     }; 
    }; 
    // If zoom ok load marker data for map tile 
    if (map.getZoom() > 10){ 
     var bnds = []; 
     var bounds = map.getBounds(); 
     bnds[0] = bounds.getNorthEast().lat(); 
     bnds[1] = bounds.getNorthEast().lng(); 
     bnds[2] = bounds.getSouthWest().lat(); 
     bnds[3] = bounds.getSouthWest().lng(); 

      $.ajax({ 
      url : base_url+"trackplanner/getpois", 
      type : 'POST', 
      data : {poirange : bnds}, 
      success: function(data) { 
       if(data.length > 0){ 
        var obj = $.parseJSON(data); 
        $.each(obj,function(i,poi){ 
         var marker = null; 
         var infowindow = null; 
         var infostr = '<div id="trackplanner_poiwin"><b>'+poi.name+'</b><br />'+poi.street+'<br />'+poi.postalcode+' '+poi.city+'<br />'+poi.phone+'<br />'; 
         if(poi.mail != ''){infostr = infostr + '<a href="mailto:'+poi.mail+'">'+poi.mail+'</a><br />'}; 
         if(poi.web != ''){infostr = infostr + '<a href="'+poi.web+'">'+poi.web+'</a>'}; 
         infostr = infostr + '</div>' 
         infowindow = new google.maps.InfoWindow({ 
          content: infostr 
         }); 
         marker = new google.maps.Marker({ 
          position: new google.maps.LatLng(poi.lat,poi.lng), 
          icon:'images/'+ poi.category +'.png', 
          title: poi.name, 
          map: map 
         }); 
         poiMarker.push(marker); 
         google.maps.event.addListener(marker, 'click', function() { 
          infowindow.open(map,marker); 
         }); 
        }); 
       } 
      }, 
      error: function() {console.log('error');} 
      }); 
    };  
}; 

這些都是聽衆:

google.maps.event.addListener(map, 'dragend', function() { 
    displayPois(); 
}); 
google.maps.event.addListener(map, 'zoom_changed', function() { 
    displayPois(); 
}); 

是否有任何改進性能的選項?聽音事件是否適合加載POI? POI在地圖上大約爲30-40。

最好的問候......

回答