2012-03-21 76 views
0

我每秒鐘都有一次加載一個標記。有50個,需要一段時間來加載所有這些。因此,爲了表明它們仍在加載,我已將其動畫設置爲反彈。但一旦他們全部加載,我想停止彈跳動畫。我怎麼做??在所有標記加載後停止彈跳標記

var geocoder; 
var map; 
var addresses = new Array(); 
var infowindow; 
var theInterval; 

function initialize() { 
    geocoder = new google.maps.Geocoder(); 
    var latlng = new google.maps.LatLng(42.095287, -79.3185139); 
    var myOptions = { 
     maxZoom: 14, 
     zoom: 9, 
     center: latlng, 
     mapTypeId: google.maps.MapTypeId.ROADMAP, 
    }; 
    map = new google.maps.Map(document.getElementById("map_canvas"), myOptions); 
    infowindow = new google.maps.InfoWindow({}); 
} 

$(document).ready(function() { 
    getAddresses(); 
    theInterval = setInterval("codeAddress()", 1000); 
}); 

function getAddresses() { 
    $('.LocationAddress').each(function() { 
     addresses.push($(this).text()); 
    }); 
} 

function codeAddress() { 
    if (addresses.length == 0) { 
     clearInterval(theInterval); 
    } 
    var addy = addresses.pop(); 
    geocoder.geocode({ 
     'address': addy 
    }, function (results, status) { 
     if (status == google.maps.GeocoderStatus.OK) { 
      map.setCenter(results[0].geometry.location); 
      var marker = new google.maps.Marker({ 
       position: results[0].geometry.location, 
       map: map, 
       title: addy, 
      animation: google.maps.Animation.BOUNCE, 

      }); 

      //Adding a click event to the marker 
      google.maps.event.addListener(marker, 'click', function() { 
       infowindow.setContent('<div id=\"infowindow\" style=" height:100px;>' + '<div id=\"LeftInfo\">' + "Hello World!" + '</div>' + '</div>'); 
       infowindow.open(map, this); 
      }); 
     } 

    }); //Geocoder END 
} 

回答

0

保留所有標記的列表。

當一切都加載時,循環但停止其動畫。

在其他消息,這個:http://econym.org.uk/gmap/geomulti.htm值得一讀。它的舊 - 指的是API的V2,否則信息仍然相關。

您還有一個錯誤的錯誤。應該在pop之後調用clearInterval。您當前的設置仍然會再次調用該函數 - 即使該數組爲空。