Here is how I would do it. I will just write the steps to execute (the algorithm), not the actual code ...
1) Initial state: nothing is selected in the drop-down list β visualize all labels (through the for (i = 0; i < cities.length; i++){ createMarker(cities[i]);} loop for (i = 0; i < cities.length; i++){ createMarker(cities[i]);} )
2) The user selects a dropdown value
3) clear all markers β map without markers
4) filter cities by value in the drop-down menu
5) display markers only for filtered cities: for (i = 0; i < filteredCities.length; i++){ createMarker(cities[i]);}
6) now your map shows only markers for filtered cities.
I donβt know the GMaps API to tell you how to remove a marker, but this should be easy :)
source share