【发布时间】:2023-06-01 20:53:01
【问题描述】:
我有以下添加地图标记集群的 jQuery 代码:
markerCluster = new MarkerClusterer(map);
我正在使用 markerCluster.addMarker(Marker); 将单个标记添加到集群(页面底部的完整代码块)。
我的问题是我的集群默认没有附加图像。
我可以做到以下几点:
var options = 'an image path';
markerCluster = new MarkerClusterer(map,markers,options);
但是,由于 options 是第三个参数,我有效地覆盖了第二个参数。有没有办法在不覆盖标记的情况下将图像设置为 MarkerCluster?
(function () {
var address = response[key]["address"];
$.getJSON('http://maps.googleapis.com/maps/api/geocode/json?address='+response[key]["post_code"]+'&sensor=false', null, function (data) {
var p = data.results[0].geometry.location
var latlng = new google.maps.LatLng(p.lat, p.lng);
var Marker = new google.maps.Marker({
position: latlng,
map: map,
content: address
});
markerCluster.addMarker(Marker);
google.maps.event.addListener(Marker, 'click', function () {
infowindow.setContent(this.content);
infowindow.open(map, this);
});
});
})();
【问题讨论】:
-
请提供一个Minimal, Complete, Tested and Readable example 来证明该问题。你是如何创建
markerCluster的?您应该能够在添加任何带有空数组的标记之前创建它。
标签: jquery google-maps google-maps-api-3