I have not tested this code, so there may be typos or errors, but it should give you this idea.
First, define a callback to set all the markers to a regular icon (before resetting any previously clicked markers) and set the current marker icon of the marker pressed to the selected icon:
var markerCallback = function() { for (var i=0; i<arrayOfMarkers.length; i++) { arrayOfMarkers[i].setIcon(normalIcon); } this.setIcon(selectedIcon); }
Then assign a callback to the click event on each token like this:
google.maps.event.addListener(marker, 'click', markerCallback);
Of course, some code improvements can be made. For example, you may not want normalIcon , selectedIcon and arrayOfMarkers be global variables, as the code above suggests. And if you have a lot of markers, you probably want to track the previously selected marker instead, rather than have a for loop reset icon on each of them.
But, as I said, this should give you this idea.
Trott
source share