简体   繁体   English

我们如何在Google Maps API中删除绑定到标记的标签

[英]How do we remove labels bound to markers in google maps api

I am using: > 我正在使用:>

ruler1 = new google.maps.Marker({
    position: map.getCenter() ,
    map: map,
    draggable: true
  });

to create a marker and then create and bind a label to it as below: 创建标记,然后创建标签并将其绑定到标签,如下所示:

ruler1label = new Label({ map: map });
ruler1label.bindTo('position', ruler1, 'position');

However, when removing the marker by: ruler1.setMap(null) which removes the marker but leaves the label behind. 但是,通过以下ruler1.setMap(null)删除标记时: ruler1.setMap(null)将删除标记,但将标签留在后面。 I tried unbinding the label to remove it by ruler1label.setLabel(null) ; 我尝试解除标签的绑定以通过ruler1label.setLabel(null)删除它; but it does not work. 但它不起作用。 How can I remove these labels? 如何删除这些标签? I have appended a screenshot to make it clear. 我已经添加了一个截图以使其清晰。 在此处输入图片说明

Bind the map variable as well: 还要绑定map变量:

ruler1label.bindTo('map', ruler1, 'map');

Then this: 然后这样:

ruler1.setMap(null);

should hide both. 应该同时隐藏两者。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM