markerclusterer不工作?

时间:2012-01-16 13:44:03

标签: google-maps-api-2 markerclusterer

大家好,

我正在制作一张带有我们公司客户标记的谷歌地图,以便销售人员可以轻松制作旅行指南。然而,我有很多标记,所以我需要聚集它们来正确加载它们。现在我发现一些网站说,这个标记包装是最快的,但是如果我试图实现它它不起作用(我不是擅长编程:()但也许有人在这里确实知道我做错了这里是我正在使用的代码。 从.xml文件中获取标记也发现这两个网站,但即使有这个帮助我也无法弄清楚我做错了什么

http://groups.google.com/group/google-maps-api/browse_thread/thread/a9cd6ed3ae8eabe6/a07a3b9ae7aae196  http://www.svennerberg.com/examples/markers/markerPerformance.html#

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
  <head>
    <title>Google Maps</title>
    <script src="js/markerclusterer.js" type="text/javascript"></script>
    <script src="http://maps.google.com/maps?file=api&amp;v=2&amp;sensor=false&amp;key=ABQIAAAAPDUET0Qt7p2VcSk6JNU1sBSM5jMcmVqUpI7aqV44cW1cEECiThQYkcZUPRJn9vy_TWxWvuLoOfSFBw" type="text/javascript"></script>
  </head>
  <body onunload="GUnload()">

    <!-- you can use tables or divs for the overall layout -->


           <div id="map" style="width: 550px; height: 450px"></div>


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

    if (GBrowserIsCompatible()) {

      // A function to create the marker and set up the event window
      function createMarker(point,html) {
        var marker = new GMarker(point);
        GEvent.addListener(marker, "click", function() {
          marker.openInfoWindowHtml(html);
        });
        return marker;
      }


      // This function picks up the click and opens the corresponding info window
      function myclick(i) {
        GEvent.trigger(gmarkers[i], "click");
      }


      // create the map
      var map = new GMap2(document.getElementById("map"));
      map.addControl(new GLargeMapControl());
      map.addControl(new GMapTypeControl());
      map.setCenter(new GLatLng( 51.907787,5.359741), 9);
      map.enableScrollWheelZoom();


      // Read the data from example.xml
      GDownloadUrl("test.xml", function(doc) {
        var xmlDoc = GXml.parse(doc);
        var markers = xmlDoc.documentElement.getElementsByTagName("marker");

        for (var i = 0; i < markers.length; i++) {
          // obtain the attribues of each marker
          var lat = parseFloat(markers[i].getAttribute("lat"));
          var lng = parseFloat(markers[i].getAttribute("lng"));
          var point = new GLatLng(lat,lng);
          var html = markers[i].getAttribute("html");
          // create the marker
          var marker = createMarker(point,html);
          map.addOverlay(marker);
          markers.push(marker);
        }
      });
      var markerCluster = new MarkerClusterer(map, markers);
    }

    else {
      alert("Sorry, the Google Maps API is not compatible with this browser");
    }


    //]]>
    </script>
  </body>

</html>

1 个答案:

答案 0 :(得分:3)

由于谷歌地图v2已被弃用,您应该将代码重写为v3! 在这里,您可以找到有关如何集成markerclusterer的一些示例:Click here for Reference