Question

Hi everyone,

I'm making a google map with markers of our company's customers,so that the sales people can make an easy travel guide. However i got alot of markers so i need to cluster them to load them properly.Now i found a few sites that said that markerclusterer was the fastest of the all however if i try to implement it it doesn't work (i'm not good at programming :( ) however maybe someone here does know what i'm doing wrong here is the code i'm using. getting the markers out of the .xml file also found these 2 websites however even with this help i can't figure out what i'm doing wrong

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>
Was it helpful?

Solution

Because of google maps v2 is deprecated you should rewrite your code to v3! Here you find some examples of how to integrate the markerclusterer:Click here for Reference

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top