0

我刚开始使用 google maps api 的第 3 版,我正在做一个简单的集群实现,但我不能让它工作。也许你可以看到我的错误在哪里,并帮助我让它工作:

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);
    }

更新 这是我看到的错误:

在此处输入图像描述

4

2 回答 2

1

对于 Google API 版本 3,您需要MarkerClustererMarkerClustererPlus。看起来您正在为 Google Maps API 版本 2 使用 MarkerClusterer。

于 2011-08-21T19:02:51.840 回答
0

首先,我假设您已经加载了所有需要的库(包括用于集群的库)并且没有出现 JS 错误。如果不是这样并且您有疑问,请报告您收到的所有错误和您加载的库。

尝试提供 maxZoom 级别:

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

然后,当您看到地图时,缩小并检查它是否会将标记分组。

于 2011-08-21T13:36:43.617 回答