Is there a simple way to set up checkboxes to toggle (on/off) KML layers for Google Maps v3? I\'ve come across these articles, but none of them have worked for me.
For toggling kml layer you can try this function:
/** Toggles layer
* @param {google.maps.KmlLayer} layer
* @param {google.maps.Map} map
**/
function toggleLayer( layer, map ){
layer.setMap( layer.getMap() ? null : map );
}
Store your layers in array for farther actions (e.g. toggling).
Then you can toggle layer by it's index on that array:
toggleLayer( layersArray[index], map );
Or to apply toggling to all layers:
for( var index = 0; index < layersArray.length; ++index){
toggleLayer( layersArray[index], map );
}