重叠标记谷歌地图

时间:2015-11-19 14:25:30

标签: javascript google-maps google-maps-api-3 overlapping

我需要穿上我的制图数据库。我设置了表格和页面,用于正确获取坐标和功能,以及地图的视觉。 现在有8000个记录在同一坐标中。如何创建重叠?

<html > 
 <head> 
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" /> 
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/> 
<title>Mappa Veicoli</title> 
<script src="https://maps.googleapis.com/maps/api/js?                   
       key=xxxxxxxxxxxxxxx" 
        type="text/javascript"></script> 

<script type="text/javascript"> 
//<![CDATA[ 

var customIcons = { 
  FRANCIA: { 
    icon: '../immig/bandiere/blue_MarkerA.png' 
  }, 
  GERMANIA: { 
    icon: './immig/bandiere/pink_MarkerA.png' 
  }, 
  USA: { 
    icon: '../immig/bandiere/darkgreen_MarkerA.png' 
  } 
  , 
  SPAGNA: { 
    icon: '../immig/bandiere/green_MarkerA.png' 
  } 
}; 

function load() { 
  var map = new google.maps.Map(document.getElementById("map"), { 
    center: new google.maps.LatLng(12.444, 14.2 ), 
    zoom: 13, 
    mapTypeId: 'roadmap' 
  }); 
  var infoWindow = new google.maps.InfoWindow; 

  // Change this depending on the name of your PHP file 
  downloadUrl("xmleicoli.php", function(data) { 
    var xml = data.responseXML; 
    var markers = xml.documentElement.getElementsByTagName("marker"); 
    for (var i = 0; i < markers.length; i++) { 
      var cognome = markers[i].getAttribute("Cognome"); 
      var nome = markers[i].getAttribute("Nome"); 
      var type = markers[i].getAttribute("Nazione"); 
      var address = markers[i].getAttribute("Residenza"); 

      var point = new google.maps.LatLng( 
          parseFloat(markers[i].getAttribute("lat")), 
          parseFloat(markers[i].getAttribute("lng"))); 
      var html = "<b>" + cognome + "," + nome + "</b> <br/>" +       
           address; 
      var icon = customIcons[type] || {}; 
      var marker = new google.maps.Marker({ 
        map: map, 
        position: point, 
        icon: icon.icon 
      }); 
      bindInfoWindow(marker, map, infoWindow, html); 
    } 
  }); 
          } 

  function bindInfoWindow(marker, map, infoWindow, html) { 
  google.maps.event.addListener(marker, 'click', function() { 
    infoWindow.setContent(html); 
    infoWindow.open(map, marker); 
  }); 
    } 

    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() {} 

//]]> 

 </script> 

 </head> 

 <body onload="load()"> 
<div id="map" style="width: 1200px; height:800px"></div> 
 </body> 

     </html>

1 个答案:

答案 0 :(得分:0)

在这种情况下,您需要稍微移动每个标记,使它们不会相互重叠,并且for表示有更多标记分组,您可以使用标记群集,您可以在StackOverflow中看到许多示例

对于标记yuo可以设置lat的差异很小的位置,例如在同一原始位置为每个标记添加+ 0.00001