javascript - Animating different markers API V3 Google Maps -


i have got markers in map , wanted animate 1 or marker depending in 1 made "click". animation work last marker create , not others ones. tried make marker array same problem. here code:

<script type="text/javascript">       var marker = null;     var address = null;     var altura = null;  function codeaddress() {   altura = document.getelementbyid('altura').value;   address = document.getelementbyid('address').value + ' ' + altura ;   geocoder.geocode( { 'address': address}, function(results, status) {     if (status == google.maps.geocoderstatus.ok) {       map.setcenter(results[0].geometry.location);     // marker       marker = new google.maps.marker({           map: map,           icon: document.getelementbyid('icono').value,           position: results[0].geometry.location,           animation: google.maps.animation.drop       });     // animating listener       google.maps.event.addlistener(marker, 'click', togglebounce);     } else {       alert('error: ' + status);     }   }); }  function togglebounce() {   if (marker.getanimation() != null) {     marker.setanimation(null);   } else {     marker.setanimation(google.maps.animation.bounce);   } }  </script> 

thanks in advance.

you need keep references markers want animate, set animation on correct one. code posted has 1 marker.

one way of solving problem function closure:

function createmarker(latlng, address, icon){     // marker       var marker = new google.maps.marker({           map: map,           icon: icon,           position: latlng,           animation: google.maps.animation.drop       });     // animating listener       google.maps.event.addlistener(marker, 'click', function() {         if (marker.getanimation() != null) {           marker.setanimation(null);         } else {           marker.setanimation(google.maps.animation.bounce);         }       }); } 

working example


Comments

Popular posts from this blog

java - activate/deactivate sonar maven plugin by profile? -

python - TypeError: can only concatenate tuple (not "float") to tuple -

java - What is the difference between String. and String.this. ? -