Google Maps API filter 'title'

Asked

Viewed 144 times

0

Good night,

I create the markers on the map using the method:

    function addMarkersLabel() {
        var latlngbounds = new google.maps.LatLngBounds();
        for (var i in points) {
            var marker = new MarkerWithLabel({
                position: points[i].latLng,
                title: points[i].titulo,
                icon: points[i].icone,
                zIndex: points.length - Number(i),
                map: GMaps,
                labelContent: points[i].labelContent,
                labelAnchor: points[i].labelAnchor,
                labelClass: points[i].labelClass
            });

            addMarkerListener(marker, points[i].id);
            markers.push(marker);
            latlngbounds.extend(marker.position);
        }
    }

But I need to allow after the map is created to show/hide the markers, using as filter the title field of the markers, if the title is equal to X, display, otherwise hidden.

  • 1

    Within your variable "markers", you have all the objects of Marker, ie, make an iteration on this Array "markers" and check the property title of each one. If your condition is true, then do something, if not, do something else.

  • But what is the command to access the 'title' property? for (var i = 0; i < markers.length; i++) { var Marker = markers[i]; }

  • Debug your code, see what’s inside markers[i], because I don’t know how this method creates the object. Maybe it’s even markers[i].title, but I’m not sure, so the best thing to do is to debug the code. Use the console.log() and see what returns in Console browser.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.