Question

I just started using the version 3 of the google maps api, and i am making a simple implementation of clustering, but i cant make it work. Maybe you can see where is my error, and help me making it work:

var map;

function runmap() {
        //Prepare cordinates
        var myLatlng = new google.maps.LatLng(-34.397, 150.644);
        //Prepare other options
        var myOptions = {
        zoom: 3,
        center: myLatlng,
        mapTypeId: google.maps.MapTypeId.ROADMAP
        //,disableDefaultUI: true//Uncoment to disable map controls
        };

        //Prepare map using de destination id(in the html page) and the options
        map = new google.maps.Map(document.getElementById("map_canvas"),myOptions);

        //Adding markers(Search marker options for more options)
         var marker = new google.maps.Marker({
         position: myLatlng, 
         map: map,
         title:"Zdravo",
         icon:"djole.png"//Change the icon of the marker
         });

        var marker2 = new google.maps.Marker({
         position: new google.maps.LatLng(-34.597, 150.744), 
         map: map,
         title:"Zdravo",
         icon:"djole.png"//Change the icon of the marker
         });

         var marker3 = new google.maps.Marker({
         position: new google.maps.LatLng(-34.290, 150.444), 
         map: map,
         title:"Zdravo",
         icon:"djole.png"//Change the icon of the marker
         });


        var markers = [];
    markers.push(marker);
    markers.push(marker2);
    markers.push(marker3);
    var markerCluster = new MarkerClusterer(map, markers);
    }

Update This is the error i see:

enter image description here

Was it helpful?

Solution

You need the MarkerClusterer or MarkerClustererPlus for Google API version 3. It looks like you are using MarkerClusterer for Google Maps API version 2.

OTHER TIPS

First, I assume you have loaded all the needed libraries (included the one for the clustering) and you get no JS errors. If that is not so and you have doubts, please report all the errors you get and libraries you load.

Try to supply maxZoom level:

var markerCluster = new MarkerClusterer(map, markers, { maxZoom: 10 });

Then when you see the map, zoom out and check if it would group the markers.

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