我有一个非常简单的标记聚类示例,它不起作用(我已经评估了论坛中的很多帖子)。 我的问题是地图上有13个标记,但无法将它们聚类。
在这下你会找到我的javascript代码。我按照这个例子: http://google-maps-utility-library-v3.googlecode.com/svn/trunk/markerclusterer/docs/examples.html
在我的HTML中,我包括了markerclusterer.js和markerclusterer_compiled.js
提前谢谢
function initialize(){
var myOptions = {
zoom: 4,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById('map'), myOptions);
var pos = new google.maps.LatLng(-39.431441,-71.286622);
map.setCenter(pos);
var all = [
[" -41.8675 ", " -73.827697"],
[" -23.65 ", " -70.4"],
[" -42.48014 ", " -73.762414"],
[" -20.2167 ", " -70.142223"],
[" -29.906301 ", " -71.250204"],
[" -39.272254 ", " -71.977629"],
[" -41.3167 ", " -72.9833"],
[" -22.908707 ", " -68.199716"],
[" -33.4625266 ", " -70.6512506"],
[" -39.819586 ", " -73.24521"],
[" -33.045646 ", " -71.620361"],
[" -33.024527 ", " -71.55234"],
[" -43.1216233 ", " -74.0300122"],
];
for (var i = 0; i < 25; i++) {
var lat = all[i][0];
var lng = all[i][1];
var latLng = new google.maps.LatLng(lat, lng);
var marker = new google.maps.Marker({map: map, position: latLng,});
all.push(marker);
}
var markerCluster = new MarkerClusterer(map, all);
};
答案 0 :(得分:0)
markercluster采用google.maps.Marker对象数组,“all”数组是一个数字数组,最后你推送一些google.maps.Markers。
function initialize() {
var pos = new google.maps.LatLng(-39.431441,-71.286622);
var myOptions = {
zoom: 4,
center: pos,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById('map'), myOptions);
map.setCenter(pos);
var all = [
[-41.8675, -73.827697],
[-23.65, -70.4],
[-42.48014, -73.762414],
[-20.2167, -70.142223],
[-29.906301, -71.250204],
[-39.272254, -71.977629],
[-41.3167, -72.9833],
[-22.908707, -68.199716],
[-33.4625266, -70.6512506],
[-39.819586, -73.24521],
[-33.045646, -71.620361],
[-33.024527, -71.55234],
[-43.1216233, -74.0300122]
];
var gmarkers = [];
for (var i = 0; i < all.length; i++) {
var lat = all[i][0];
var lng = all[i][1];
var latLng = new google.maps.LatLng(lat, lng);
var marker = new google.maps.Marker({map: map, position: latLng,});
gmarkers.push(marker);
}
var markerCluster = new MarkerClusterer(map, gmarkers);
};
google.maps.event.addDomListener(window, 'load', initialize);