Marker
objects have setIcon()
method which can be used to change the icon of the marker. If you want to change icon every x seconds, then you must call setIcon()
in setInterval()
function:
var color = "red";
setInterval(function() {
if(color === "blue") {
// set color red
marker.setIcon(createMarkerIcon("some text", {
bgColor:"#FF0000" }));
// If you have multiple markers, uncomment below and comment above
/*for(var i = 0; i < markerArray.length; i++) {
markerArray[i].setIcon("http://labs.google.com/ridefinder/images/mm_20_red.png");
}*/
color = "red";
} else {
// set color blue
marker.setIcon(createMarkerIcon("some text again", {
bgColor:"#0900FF" }));
// If you have multiple markers, uncomment below and comment above
/*for(var i = 0; i < markerArray.length; i++) {
markerArray[i].setIcon("http://labs.google.com/ridefinder/images/mm_20_red.png");
}*/
color = "blue";
}
}, 1000 ); // every 1 second
You should add this after you define marker
(or if you have multiple markers, add after you push created markers to marker array). Note that I used your createMarkerIcon()
as parameter for setIcon()
.
DEMO -- UPDATED FOR MULTIPLE MARKERS