I know there have been some questions with related title, but I didn't find the answer that would suit me.
Here is my issue :
I am trying to print a map, with multiple marker in it, generated via a database. I have, below the map, some checkbox that would allow me to filter the marker on the map.
So, the first time I am loading the map, everything is well filtred (depending on what is checked by default), by I don't really understand how to add / remove marker from the map once it is already initialized. Do I have to reload the map, or am I missing something ?
Here is the relevant code :
<form> <input class="test" type="checkbox" name="type" value="1" onclick="test()" checked/>1<br/> <input class="test"type="checkbox" name="type" value="2" onclick="test()" checked/>2<br/> <input class="test"type="checkbox" name="type" value="3" onclick="test()" checked/>3<br/> <input class="test"type="checkbox" name="type" value="4" onclick="test()" checked/>4<br/> <script> var checkedValues = $('input:checkbox:checked').map(function() { return this.value; }).get().join('-'); function fetchPlace(filtreType){ $.ajax({ url: "ajaxmap.php?type=" + filtreType, type : 'GET', dataType: 'json', success : function(data) { // Loop through our array of markers & place each one on the map for( i = 0; i < data.marker.length; i++ ) { var myLatlng = new google.maps.LatLng(data.marker[i].log,data.marker[i].lat); var marker = new google.maps.Marker({ position: myLatlng, map: map, title: 'Hello World!' }); } } , error: function(){ /// traiter les erreur }, async : true }); }; function test (){ var checkedValues = $('input:checkbox:checked').map(function() { return this.value; }).get().join('-'); fetchPlace(checkedValues); }; fetchPlace(checkedValues); Thanks for any help you could provide.
Loneept
filterTypein your ajax success function. This way you can easily reference them, toggle their display on the map, etc. Do you need an example?