Google Maps v3 JQuery 引入了以下获取标记的方法:
$map.gmap('get', 'markers');
我正在尝试这个,但得到一个空数组。这是我正在使用的代码:
var smap = $('#smap');
$(window).load(function() {
/* Initialize Map */
smap.gmap({
center: '34.913167, -94.618089',
zoom: 5
}).bind('init', function() {
/* Add markers */
$.getJSON('static/stninfo.js', function(data) {
$.each(data, function(index, stn) {
var latlng = (stn.loc).substring(0, stn.loc.length - 4);
smap.gmap('addMarker', {
position: latlng,
bounds: false,
id: stn.stnid
}).click(function() {
smap.gmap('openInfoWindow', {
content: '<strong>' + stn.name + '</strong></br>' + latlng
}, this);
});
});
});
var imap = smap.gmap('get', 'map');
var imarkers = smap.gmap('get', 'markers');
console.log(imap);
console.log(smap.gmap('get', 'markers'));
/* Initialize clusters */
smap.gmap('set', 'MarkerClusterer', new MarkerClusterer(imap, imarkers));
});
});
根据代码,我需要这个才能使用 MarkerClusterer。我在控制台中没有收到任何错误。至于console.log
s 的结果,第一个(imap)正确返回了地图对象。第二个(标记列表)只返回一个空数组(“[]”)。
MarkerClusterer 代码似乎没有问题;我的怀疑是我错误地添加了标记。关于这里有什么问题的任何见解?
我一直以此为参考:https ://code.google.com/p/jquery-ui-map/wiki/jquery_ui_map_v_3_sample_code