1

如何在 Google Maps API 中使用 MarkerClusterer?我尝试使用它,但它不起作用。我的代码编写如下。

function InitializeMap(lat, lng, location, username, town, is_paid) {
   var myOptions;
   var latlng = new google.maps.LatLng(lat, lng);

   if (is_paid != "True") {
      myOptions = {
         zoom: 10,
         center: latlng,
         scrollwheel: false,
         streetViewControl: false,
         //navigationControlOptions: {style: google.maps.NavigationControlStyle.SMALL},
         //scaleControl: false,
         navigationControl: false,
         mapTypeId: google.maps.MapTypeId.ROADMAP
      };
   }
   else {
      myOptions = {
         zoom: 10,
         center: latlng,
         scrollwheel: true,
         streetViewControl: true,
         navigationControlOptions: { style: google.maps.NavigationControlStyle.SMALL },
         mapTypeId: google.maps.MapTypeId.ROADMAP
      };
   }

   map = new google.maps.Map(document.getElementById('map'), myOptions);
   var mcOptions = {gridSize: 100, maxZoom: 10};

   generateMarkers(location, is_paid);
   generateUserMarker(lat, lng, username, town, is_paid);

   alert(groupMarkers.length);

   var mc = new MarkerClusterer(map, groupMarkers, mcOptions);
   //mc.addMarkers(groupMarkers,true);
   alert("hello");

}

function generateMarkers(locations, is_paid) {
   var marker
   for (var i = 0; i < locations.length; i++) {
      createMarker(new google.maps.LatLng(locations[i][0], locations[i][1]), locations[i][2], locations[i][3], is_paid);
   }
}

function createMarker(pos, name, town, is_paid) {
   var infowindow;

   var marker = new google.maps.Marker({
      position: pos,
      map: map,  // google.maps.Map 
      title: name,
      icon: "images/red.png"
   });

   groupMarkers.push(marker);

}
4

0 回答 0