A
A
Alexander Andreev2017-10-16 11:14:38
JavaScript
Alexander Andreev, 2017-10-16 11:14:38

How to access a marker on a Google map by id?

There is a map with a bunch of objects, objects in the form of markers. When you click on a marker, you need to hide everything except the clicked one. How to hide all markers found in the example in the docks:

// Sets the map on all markers in the array.
    function setMapOnAll(map) {
      for (var i = 0; i < markers.length; i++) {
        markers[i].setMap(map);
      }
    }

    // Removes the markers from the map, but keeps them in the array.
    function clearMarkers() {
      setMapOnAll(null);
    }

so-called call clearMarkers(). But I don't understand how to activate the clicked one after clearMarkers(). According to the idea, you can refer to it by id or some other identifier, but for the time being I have not found anything similar either in the docks or on the forums.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
freeExec, 2017-10-16
@maler1988

And you won’t find it, all your markers must be kept in their arrays. Scroll through and find the right one.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question