The easiest way is to create mouseover / mouseout event handlers for each marker to update the color of the label text.
// creates a marker with a closure for the event functions. function createMarker(latLng, text, label) { var marker = new google.maps.Marker({ position: latLng, map: map, label: {text: label, color: "white"} }); google.maps.event.addListener(marker, "mouseover", function(evt) { var label = this.getLabel(); label.color="black"; this.setLabel(label); }); google.maps.event.addListener(marker, "mouseout", function(evt) { var label = this.getLabel(); label.color="white"; this.setLabel(label); }); return marker; }
proof of violin concept
code snippet:
var geocoder; var map; function initialize() { map = new google.maps.Map( document.getElementById("map_canvas"), { center: new google.maps.LatLng(37.4419, -122.1419), zoom: 13, mapTypeId: google.maps.MapTypeId.ROADMAP });
html, body, #map_canvas { height: 100%; width: 100%; margin: 0px; padding: 0px }
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyCkUOdZ5y7hMm0yrcCQoCvLwzdM6M8s5qk"></script> <div id="map_canvas"></div>
source share