我使用

uj5u.com熱心網友回復:
好的,我發現了問題。看起來我必須在每次重新渲染期間從集群器中清除標記。更新的鉤子代碼:
let markerClusterer: MarkerClusterer | null = null;
let markers: google.maps.Marker[] = [];
useEffect(() => {
markerClusterer?.clearMarkers();
markers.forEach((marker) => marker.setMap(null));
const markers = addresses.map((address) => {
new window.google.maps.Marker({
position: {
lat: address.attributes.lat,
lng: address.attributes.lng,
},
map: map,
});
});
new MarkerClusterer({ map, markers });
}, [addresses, map, mapParams]);
感謝 Piero Alberto 在他的問題中提供的線索
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/532289.html
