Google Maps API v3 - 如何清除叠加层? [英] Google Maps API v3 - How to clear overlays?

查看:33
本文介绍了Google Maps API v3 - 如何清除叠加层?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Google Maps API v2 中,我使用 map.clearOverlays() 删除标记并重新绘制它们.

In Google Maps API v2, I was using map.clearOverlays() to remove the marker and draw them again.

如何使用 Google Maps API v3 做到这一点?

How can I do that using Google Maps API v3 ?

谢谢

推荐答案

参见 此处 有关向您开放的各种选项的详细信息,但您现在必须遍历标记并单独删除它们.您的代码应如下所示:

See here for details on the various options open to you but you now have to iterate through the markers and remove them individually. Your code should look something like this:

var markers = [];

function clearOverlays() {
 while(markers.length) { markers.pop().setMap(null); }
  markers.length = 0;
}

markers.push(marker);
google.maps.event.addListener(marker,"click",function(){});

这篇关于Google Maps API v3 - 如何清除叠加层?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆