1

我多年来一直坚持这一点。我创建了一个地图,它使用 php 从 mysql 数据库中提取数据。一切都很好,我正在为每个标记获取信息窗口。我添加了运行良好的聚类代码。现在它只在单击标记时显示相同的信息框。我已尝试在此站点上发布与我的问题相关的解决方案,但似乎找不到解决方案。任何帮助,将不胜感激

var customIcons = {
  BB: {
    icon: '/assets/img/bb-icon.png',
    shadow: 'http://labs.google.com/ridefinder/images/mm_20_shadow.png'
  },
  SC: {
    icon: '/assets/img/sc-icon.png',
    shadow: 'http://labs.google.com/ridefinder/images/mm_20_shadow.png'
  },
  BOTH: {
    icon: '/assets/img/both-icon.png',
    shadow: 'http://labs.google.com/ridefinder/images/mm_20_shadow.png'
  }
};

function load() {
    var cluster = [];
  var map = new google.maps.Map(document.getElementById("maplocation"), {
    center: new google.maps.LatLng(<?php echo $coord; ?>),
    zoom: 9,
    mapTypeId: 'roadmap'
  });
  var infowindow = new google.maps.InfoWindow();

  // Change this depending on the name of your PHP file
  downloadUrl("/generate-coords.php?map=<?php echo $_GET['area']; ?>", function(data) {
    var xml = data.responseXML;
    var markers = xml.documentElement.getElementsByTagName("marker");
 for (var i = 0; i < markers.length; i++) {
        var name = markers[i].getAttribute("name");
        var thetitle = markers[i].getAttribute("name");
        var address = markers[i].getAttribute("address");
        var type = markers[i].getAttribute("type");
        var farmno = markers[i].getAttribute("farmno");
        var point = new google.maps.LatLng(
          parseFloat(markers[i].getAttribute("lat")),
          parseFloat(markers[i].getAttribute("lng")));
        var html = '<b>' + name + '</b> <br />' + address+ '<br /><a href="/fulldetails.php?farmno=' + farmno + '">More Details</a>';
        var icon = customIcons[type] || {};
        var marker = new google.maps.Marker({
           map: map,
           position: point,
           icon: icon.icon,
           shadow: icon.shadow,
           title:thetitle,
           content:html
          });
       google.maps.event.addListener(marker, 'click', (function(marker, i) {
                    return function() {
                        infowindow.setContent('<div style=height:80px;overflow:none>'+html+'</div>');
                        infowindow.open(map, this);
                    }
                })(marker, i));
             cluster.push(marker);
         }

        var markerClustererOptions = {   
           maxZoom: null,
           gridSize: 15 ,   
          title: 'Click to zoom in and see farms.'
         };  
    var mc = new MarkerClusterer(map,cluster,markerClustererOptions);
  });
}

function downloadUrl(url, callback) {
  var request = window.ActiveXObject ?
      new ActiveXObject('Microsoft.XMLHTTP') :
      new XMLHttpRequest;

  request.onreadystatechange = function() {
    if (request.readyState == 4) {
      request.onreadystatechange = doNothing;
      callback(request, request.status);
    }
  };

  request.open('GET', url, true);
  request.send(null);
}

function doNothing() {}`
4

1 回答 1

0

试试这个

google.maps.event.addListener(marker, 'click', (function(marker, i, html) {
    return function() {
        infowindow.setContent('<div style=height:80px;overflow:none>'+html+'</div>');
        infowindow.open(map, marker);
})(marker, i, html));
于 2012-12-18T12:23:26.837 回答