Using Google Maps API v3, how do I programmatically change the marker icon?
What I would like to do is, when someone hovers over a link - to have the corresponding marker icon on the map change colors to denote the marker in question.
Essentially, the same function as what Roost does.
When you hover over a home listing on the left, the corresponding marker on the right changes color
This thread might be dead, but StyledMarker is available for API v3. Just bind the color change you want to the correct DOM event using the addDomListener() method. This example is pretty close to what you want to do. If you look at the page source, change:
to something like:
That should be enough to get you moving along.
The Wikipedia page on DOM Events will also help you target the event that you want to capture on the client-side.
Good luck (if you still need it)
You can try this code
Call the
marker.setIcon('newImage.png')
... Look here for the docs.Are you asking about the actual way to do it? You could just create each
div
, and a add amouseover
andmouseout
listener that would change the icon and back for the markers.The GMaps Utility Library has a plugin called MapIconMaker that makes it easy to generate different marker styles on the fly. It uses Google Charts to draw the markers.
There's a good demo here that shows what kind of markers you can make with it.
You can also use a circle as a marker icon, for example:
and then, if you want to change the marker dynamically (like on mouseover), you can, for example: