How to set marker when already clustered

时间:2019-01-07 12:58:38

标签: javascript google-maps markerclusterer

I have google maps application using marker cluster, but I need it without marker cluster.

My code:

function makeMarker(response, markers_pelanggan, A /*, Cluster */) {
  let locations = response;
  let color;

  switch (A) {
    case 'M' : color = 'eacd20';break;
    case 'I' : color = 'ea1f1f';break;
    case 'Mb': color = '1eea3d';break;
    case 'V' : color = '1d5bea';break;
    case 'P' : color = 'ff00e1';break;
    case 'S' : color = '33ffbd';break;
  }

  markers_map = locations.map(function (location, i) {
    marker = new google.maps.Marker({
      title   : location.nomor_pela,
      icon    : 'http://chart.apis.google.com/chart?chst=d_map_pin_letter&chld=' + A + '|' + color + '|000000',
      position: location
    });

    bounds.extend(location);
    google.maps.event.addListener(marker, 'click', (function(marker, i) {
      return function() {
          infoWindow.setContent(location.content);
          infoWindow.open(map, marker);
      }
    })(marker, i));
    markers_pelanggan.push(marker);
    return marker;
  });

  // Cluster.addMarkers(markers_map);
  map.fitBounds(bounds);
}

I already try to remove the clusterer function and the result did not show the marker. only blank map. please enlighten me. best regards

1 个答案:

答案 0 :(得分:-1)

我不好,只需要添加地图即可

markers_map = locations.map(function (location, i) {
                marker = new google.maps.Marker({
                    title   : location.nomor_pela,
                    icon    : 'http://chart.apis.google.com/chart?chst=d_map_pin_letter&chld='+A+'|'+color+'|000000',
                    position: new google.maps.LatLng(location),
                    map     : map <== this one
                });

                bounds.extend(location);
                google.maps.event.addListener(marker, 'click', (function(marker, i) {
                    return function() {
                        infoWindow.setContent(location.content);
                        infoWindow.open(map, marker);
                    }
                })(marker, i));
                markers_pelanggan.push(marker);
                return marker;
            });
            // Cluster.addMarkers(markers_map);

            map.fitBounds(bounds);