Reputation: 1
I have an img inside a Google Maps infowindow html, and onclick
, I want the Marker icon of that pin to change.
Here's where I am:
The HTML within the infowindow:
<img id="1" onclick="changePin(this);" src="image.png">
Then the function:
function changePin(venue) {
if (venue.id == '1'){
google.maps.Marker[0].setIcon('images/pin1.png');
venue.id = '2';
} else {
google.maps.Marker[0].setIcon('images/pin2.png');
venue.id = '1';
}
}
It's the google.maps.Marker[0].setIcon('images/image2.png');
statement that I'm struggling with, I'm guessing I need to give each marker a name/ID/array position to address it.
Upvotes: 0
Views: 140
Reputation: 161384
You are accessing the marker incorrectly. My suggestion would be to make an array of markers, then put code in the infowindow to change the icon.
Here is an example that should help (changes the icon on mouseover and from the side bar):
http://www.geocodezip.com/v3_MW_example_hoverchange.html
Upvotes: 1