title: dynamic icon change for markers google maps
body: <p>I have studied the map class from Google and got to point where I'm able to set markers on locations I want. I wanted to have icons dynamically updated on "mouse events"   </p>
  
  <pre><code>    var neighborhoods = [
      [54.50266744485844,  18.540940856933616],
      [54.49848076437959,  18.540254211425804],
      [54.49190082846816, 18.518968200683616],
      [54.4040671009359,  18.608918762207054],
      ];
  
      var markers = [];
      var map;
  </code></pre>
  
  <p>And for to put markers I use function as below.</p>
  
  <pre><code>     function setMarkers(map) {
  
        var image = {
        url: '/images/icon1.png',
     anchor: new google.maps.Point(0, 32)
     };
      var shape = {
      coords: [1, 1, 1, 20, 18, 20, 18, 1],
      type: 'poly'
    };
  
  
      for (var i = 0; i &lt; neighborhoods.length; i++) 
         {
          var neighborhood = neighborhoods[i];
          var marker_temp = new google.maps.Marker
          ({
          position: {lat: neighborhood[0], lng: neighborhood[1]},
          map: map,
          icon: image,
          shape: shape,
          title: "",
          visible:true,
          zIndex: 3
          });
          marker_temp.addListener('mouseover', function() 
          { 
          marker_temp.setOptions({icon: "/images/icon1.png"});
          });
  
          marker_temp.addListener('mouseout',  function() 
          { 
          marker_temp.setOptions({icon: "/images/icon2.png"});    
          });
  
          marker_temp.addListener('click',  function() 
          { 
          marker_temp.setOptions({icon: "/images/icon1.png"});
          });
  
  
      markers.push(marker_temp);
  }// end of for loop ----------------------------------------------------
  
       }// --- end of set markers function --------------------------------
  </code></pre>
  
  <p>Putting markers works fine and events on all of them are triggered as expected but only change of the icon from icon1.png to icon2.png works on last marker with events related to all fo them. Can anyone tell me where is error in my thinking ?</p>