Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

change marker icon on mouseover ( google maps V3 )

var image = 'bullets/_st_zzzzzzl SSS.gif';  var bar1 = new google.maps.Marker({     position: myLatLng,      map: map,     icon: image,     title: "bar number 1"        });       google.maps.event.addListener(bar1, 'mouseover', function() {         infowindow.open(map,bar1);     });      google.maps.event.addListener(bar1, 'mouseout', function() {         infowindow.close(map,bar1);     }); 

Now when im on mouseover i want the icon to change to another image i got. i tried some tips and some code but nothing works... Appreciate ur help

like image 329
t0s Avatar asked Nov 20 '11 01:11

t0s


People also ask

How do I change a marker icon dynamically in Google Maps?

You could just create each div , and a add a mouseover and mouseout listener that would change the icon and back for the markers.


1 Answers

Use marker.setIcon() function. The rest is almost the same as opening/closing infowindow in your code:

var icon1 = "imageA.png"; var icon2 = "imageB.png";  var marker = new google.maps.Marker({     position: myLatLng,     map: map,     icon: icon1,     title: "some marker" });  google.maps.event.addListener(marker, 'mouseover', function() {     marker.setIcon(icon2); }); google.maps.event.addListener(marker, 'mouseout', function() {     marker.setIcon(icon1); }); 

Note that besides using image paths in setIcon() function, you can also use google.maps.MarkerImage objects, which are very useful, especially if you want to use image sprites.

like image 187
Tomik Avatar answered Oct 07 '22 18:10

Tomik