How to remove the marker from the cluster in google map?

断了今生、忘了曾经 提交于 2019-12-08 04:59:01

问题


I have implemented cluster in google map and I want to update the map with the markers based on the checkbox selection.

I want to remove the marker from the cluster based on the custom property that I have set in the marker.

var clust = new MarkerClusterer(map, markers, {maxZoom: 14});

How can I do this? Please help me.

Thanks in advance.


回答1:


For each marker to remove:

 clust.removeMarker(marker);

For each Marker to add:

 clust.addMarker(marker);



回答2:


You need to set map null for current markercluster and then create new marker array on the basis of property you want then create new markercluster again and set to map.

var clust = new MarkerClusterer(map, markers, {maxZoom: 14});

on update property

clust.setMap(null)
var newclust = new MarkerClusterer(map, newmarkers, {maxZoom: 14});
newclust.setMap(mapobject)


来源:https://stackoverflow.com/questions/25302466/how-to-remove-the-marker-from-the-cluster-in-google-map

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!