Google Maps marker grouping

前端 未结 2 758
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-15 10:54

I\'m trying to achieve the following thing: Have different types of markers on my map for example, schools, libraries, bus stops and I want to be able to show/hide each grou

2条回答
  •  误落风尘
    2020-12-15 11:11

    You basically just need to store references to Marker objects in an array, set their type (school, bus stop, etc.) and then on some event loop through and hide/show as appropriate:

    var markers = [];
    
    // create Marker
    
    marker.locType = 'school'; //as appropriate
    
    function hideMarkersOfType(type) {
        var i = markers.length;
        while(i--) {
            if (markers[i].locType == type) {
                markers[i].setVisible(false);
            }
        }
    }
    
    // similar function showMarkersOfType() calling markers[i].setVisible(true);
    

    That should be a good start anyway.

提交回复
热议问题