Answer the question
In order to leave comments, you need to log in
How to change icons of all markers in Google Maps API?
This is my google code:
function initMap() {
var firstMarker = {lat: 50.461686, lng: 30.496442};
var secondMarker = {lat: 50.430365, lng: 30.520543};
var thirdMarker = {lat: 50.452029, lng: 30.486235};
// Create a map object and specify the DOM element for display.
var locations = [
['Bondi Beach', firstMarker, 4],
['Coogee Beach', secondMarker, 5],
['Cronulla Beach', thirdMarker, 3],
];
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 13,
center: new google.maps.LatLng(50.451756, 30.509776),
mapTypeId: google.maps.MapTypeId.ROADMAP
});
var infowindow = new google.maps.InfoWindow();
var marker, i;
for (i = 0; i < locations.length; i++) {
marker = new google.maps.Marker({
position: new google.maps.LatLng(locations[i][1], locations[i][2]),
map: map,
icon: '/html/img/map_marker.png',
});
google.maps.event.addListener(marker, 'click', (function(marker, i) {
// console.log(i)
return function() {
infowindow.setContent(locations[i][0]);
infowindow.open(map, marker);
console.log(marker);
if(marker.icon == '/html/img/map_marker.png') {
marker.setIcon('/html/img/marker_active.png');
}
else {
marker.setIcon('/html/img/map_marker.png');
}
}
})(marker, i));
}
}
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