Answer the question
In order to leave comments, you need to log in
How to change a marker in Google Maps by clicking on it?
How to change the marker image by clicking on it?
Google map on the site, I have my own markers, and by clicking on the marker I learned to change its drawing, I do this through
setIcon (); , but here's the ambush, when I click on the next marker, the previous one remains active, since I already clicked on it and changed the icon, how to reset setIcon(); what would be the default settings for all markers except the active one?
function initialize() {
var myLatLng = {lat: 55.6978, lng: 37.8592};
var locations = [
{
position: {lat: 55.6978, lng: 37.8592},
icon: {
url: "/images/icon/pinMap.png",
scaledSize: new google.maps.Size(69, 69)
}
}
];
var myMapOptions = {
.....
};
var map = new google.maps.Map(document.getElementById("map"), myMapOptions);
//marker
locations.forEach(function(o, n) {
var i = new google.maps.Marker({
position: o.position,
map: map,
icon: o.icon
}),
i.addListener("click", function() {
i.setIcon('/images/icon/pinMap2.png');
})
});
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question