【发布时间】:2014-03-02 01:21:28
【问题描述】:
我想在我的地图上使用 MarkerClusterer,但我不太了解 JavaScript。
如何在我的地图中使用 MarkerClusterer?
我需要添加集群命令,但我不太了解编码。我的代码在下面
var LocationData = [
[49.2814064, -123.1025187, "71 E Hastings St, Vancouver" ],
[49.2812336, -123.1020622, "122 E Hastings St, Vancouver" ],
[49.2813564, -123.1012253, "138 E Hastings St, Vancouver" ],
[49.2811625, -123.0985032, "242 E Hastings St, Vancouver" ]
];
function initialize() {
var map =
new google.maps.Map(document.getElementById('map_canvas'));
var bounds = new google.maps.LatLngBounds();
var infowindow = new google.maps.InfoWindow();
for (var i in LocationData) {
var p = LocationData[i];
var latlng = new google.maps.LatLng(p[0], p[1]);
bounds.extend(latlng);
var marker = new google.maps.Marker({
position: latlng,
map: map,
title: p[2]
});
google.maps.event.addListener(marker, 'click', function () {
infowindow.setContent(this.title);
infowindow.open(map, this);
});
}
map.fitBounds(bounds);
}
google.maps.event.addDomListener(window, 'load', initialize);
google.maps.event.addListener(marker, 'click', function () {
infowindow.setContent(p[2]);
infowindow.open(map, marker);
});
【问题讨论】:
-
您使用的是哪个集群插件,到目前为止您尝试过什么?
-
Google MarkerClusterer 喜欢that
标签: javascript google-maps google-maps-api-3 markerclusterer