Cluster Marker Google Maps using geoCoder

限于喜欢 提交于 2019-12-04 19:36:55

Because the geocodeing function is async you need to create the marker clusterer before the markers have been created.

what you should do is create the MarkerClusterer before you start geocoding and then instead of adding to a marker array you can instead just add it to the MarkerClusterer.

Yes, geocoding function is async. so, You can add marker in cluster later on using addMarker() method.

var markerCluster = new MarkerClusterer(map, markerArray);
for (var level in data) {
    for (var i = 0; i < data[level].length; i++) {      
      var dataAdd =  data[level][i];
      geocoder.geocode({ 'address': dataAdd.address}, function(results){            
      var marker  = new google.maps.Marker({
          map: map, 
          position: results[0].geometry.location
      });
     markerArray[i] = marker;  
     markerCluster..addMarker(marker);       
    });
    }
}    
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!