Turn on / off markers in the Google Maps API v3

I'm having trouble getting setMap (null); a feature that everyone seems to recommend working.

I believe this may be a problem with how I implemented markers.

If someone can take a look and let me know, if you see something wrong, I would really appreciate it.

LINK: http://www.dougglover.com/samples/UOITMap/v2/

Please note: the old link above does not go anywhere.

+3
source share
2 answers

, , , , markersTest. , , markersTest , , .

javascript, , / :

15  function addTestMarkers(){
16      for(var i in markersTest) {
17          var location = new google.maps.LatLng(markersTest[i][1], markersTest[i][2]);
18          marker = new google.maps.Marker({
19              position: location,
20              map: map
21          });
22      }
23  }
24  
25  // Removes the overlays from the map, but keeps them in the array
26  function clearOverlays() {
27      if (markersTest) {
28          for (i in markersTest) {
29              markersTest[i].setMap(null);
30          }
31      }
32  }

addTestMarkers, markersTest , . clearOverlays markersTest .

: markersTest, javascript markerDestinations, javascript markersTest,

markersTest = {};

addTestMarkers :

function addTestMarkers() {
    for(var i in markerDestinations) {
        var location = new google.maps.LatLng(markersDestinations[i][1], markersDestinations[i][2]);
        markersTest[i] = new google.maps.Marker({
            position: location,
            map: map
        });
    }
}

, addTestMarkers markersTest.

-2

setMap (null) ! API setVisible, .

+15

Source: https://habr.com/ru/post/1743268/


All Articles