开发者

Why clustering does not work? (google maps API V3)

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 开发者_如何学Goyou 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:

Why clustering does not work? (google maps API V3)


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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜