【问题标题】:Hiding markers Google Maps API v3 with a click通过单击隐藏标记 Google Maps API v3
【发布时间】:2015-09-10 07:03:00
【问题描述】:

我想通过单击链接 HTML 来隐藏标记。我写了一些代码,但它不起作用。谁能告诉我怎么了?

var markers = [];

var cuicui= [
     [45.710743, 4.934347],     
     [45.691894, 4.923193],
     [45.713855, 4.928156],
     [45.710238, 4.965208],
     [45.713550, 4.930187],
     [45.712871, 4.928613],
     [45.698959, 4.918937],
     [45.709566, 4.923370],
     [45.715945, 4.931199],
     [45.715824, 4.912740]
];

for (i = 0; i < cuicui.length; i++) {  
    var position = new google.maps.LatLng(cuicui[i][0], cuicui[i][1]),
      marker = new google.maps.Marker({
      position: position,
      map: map
    });

    markers.push(marker);

    google.maps.event.addListener(marker, 'click', (function(marker, i) {
      })(marker, i));   

    marker.setVisible(false);

    google.maps.event.addDomListener(document.getElementById('cuicui'), 'click', function () {
      if (marker.setVisible(false)) {
          marker.setVisible(true);
        } else {
          marker.setVisible(false);
        }
    });
} 

在我的 HTML 中,我有:

  <a style="cursor : pointer;" id="cuicui">Ici</a>

(对不起我的英语。)

【问题讨论】:

标签: google-maps google-maps-api-3 maps google-maps-markers show-hide


【解决方案1】:

而不是 setVisible();使用 setMap();

marker.setMap(map);

让它出现

marker.setMap(null);

让它不可见

【讨论】:

  • 感谢您的回答,但它仍然不起作用...但是没有报告错误
猜你喜欢
  • 2014-01-05
  • 2012-02-04
  • 2012-03-24
  • 2012-11-08
  • 1970-01-01
  • 2014-11-05
  • 1970-01-01
  • 2012-07-15
  • 2012-08-27
相关资源
最近更新 更多