How can I show or hide markers of different groups (Let's say Bars/Cinemas/Parking) , by clicking on a HTML element (a Checkbox in this case)?
my markers are generated into an array from a loop, like this:
markers[i] = new google.maps.Marker({
numero : i,
position: latLng,
map: map,
info: data.Description,
group: data.category,
});
I think I should use :
An onclick on my HTML element, with a Js function.
This Js function should contain this Gmaps Method
setVisible
Like this:
google.maps.event.addListener(marker, 'click', function() {
marker.setVisible(false); // maps API hide call
});
and a Event Trigger :
google.maps.event.trigger(markers[i], 'click');
But now how can I mix this stuff together?
Close. Assuming
markers
holds an array of all the markers in a given group, you might create anonchange
handler for the checkbox that will hide all of the markers in the group like so. In your HTML:And sometime later, in your script,
For reference, check out this fiddle.
Concept is so simple. Just define global array for marker. push all markers and onchange event show/hide the marker. Checkout following code S@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@NI
S@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@NI
thanks