0

我刚开始使用谷歌地图api的版本3,我正在做一个简单的群集实现,但我不能让它工作。也许你可以看到哪里是我的错误,并帮助我做它的工作:为什么群集不起作用? (谷歌地图API V3)

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

更新 这是我看到的错误:

enter image description here

回答

0

首先,我假设你已经装所有需要的库(包括一个用于集群的库),并且不会出现JS错误。如果不是这样并且您有疑问,请报告您获得的所有错误以及您加载的库。

去供给MAXZOOM级别:

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

然后,当你看地图,缩小并检查它是否将组标记。

+0

我需要什么其他额外的库?与标记和信息窗口相同吗?如果是的话,我确定我已经在那里。我尝试了缩放,但仍然看不到集群。 – sfrj

+0

您还需要“marker clusterer”库,它是一个插件,而不是默认的gmaps行为。请参阅此处以及工作示例(只有几行代码可用 - 将其中一个代码的源代码复制到您的文件并从此处开始调试):http://google-maps-utility-library-v3.googlecode.com/ svn/trunk/markerclusterer/ – ddinchev

+0

我刚刚添加了该库,但出现一些错误,我不明白为什么。请参阅上面的图片 – sfrj