【问题标题】:Why clustering does not work? (google maps API V3)为什么集群不起作用? (谷歌地图 API V3)
【发布时间】:2011-10-31 14:14:42
【问题描述】:

我刚开始使用 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);
    }

更新 这是我看到的错误:

【问题讨论】:

    标签: javascript html google-maps-api-3 cluster-analysis markerclusterer


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:

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

      尝试提供 maxZoom 级别:

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

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

      【讨论】:

      • 我还需要哪些额外的库?与标记和信息窗口相同吗?如果是的话,确定我已经把它们放在那里了。我尝试了缩放,但仍然看不到聚类。
      • 您还需要“marker clusterer”库,它是一个插件,而不是默认的 gmaps 行为。请参阅此处以及工作示例(这是几行有效的代码 - 将其中之一的源代码复制到您的文件并从那里开始调试):google-maps-utility-library-v3.googlecode.com/svn/trunk/…
      • 我刚刚添加了那个库,但我得到了一些错误,我不明白为什么。见上图
      • 提供您得到错误的完整页面源或指向它的链接。
      猜你喜欢
      • 1970-01-01
      • 2011-07-19
      • 2014-01-15
      • 1970-01-01
      • 2014-12-14
      • 1970-01-01
      • 2012-12-15
      • 2012-05-17
      • 1970-01-01
      相关资源
      最近更新 更多