0
我已經從這個使用的代碼:http://jsfiddle.net/ErYub/谷歌地圖標記環只顯示第一次迭代
但改變了它從我的數據庫中提取記錄:
#{
(Datacentre.find(:all, :conditions => "longitude != false").map do |d|
"var latLng = new google.maps.LatLng(#{d.latitude}, #{d.longitude})
marker#{d.id} = new MarkerWithLabel({
position: latLng,
draggable: false,
map: map,
icon: {url:'/assets/icon_red.png'}
});
markers.push(marker#{d.id});
makeDiv(#{d.id}, 15, 'Marker #');
google.maps.event.addListener(markers[#{d.id}], 'click', function(e) {
infowindow.setContent('Marker postion: ' + this.getPosition());
infowindow.open(map, this);});
"end).join
}
var clusterOptions = { zoomOnClick: false }
var markerCluster = new MarkerClusterer(map, markers, clusterOptions);
globalMarker = markers.slice();
google.maps.event.addListener(markerCluster, 'clusterclick', function(cluster) {
var content = '';
var info = new google.maps.MVCObject;
info.set('position', cluster.center_);
var markers = cluster.getMarkers();
var titles = "";
#{
(Datacentre.find(:all, :conditions => "longitude != false AND reference != ''").map do |d|
"titles = markers[#{d.id}].labelContent + "\n";
"end).join
}
的代碼在瀏覽器中顯示看起來我期望它,但只有第一個標記是顯示和信息框不顯示。
生成的代碼
function initialize() {
var center = new google.maps.LatLng(45.4214, -75.6919);
map = new google.maps.Map(document.getElementById('map'), {
zoom: 3,
center: center,
disableDoubleClickZoom: true,
mapTypeId: google.maps.MapTypeId.ROADMAP
});
var markers = [];
var infowindow = new google.maps.InfoWindow();
var latLng = new google.maps.LatLng(50.72385, -1.90664)
marker1 = new MarkerWithLabel({
position: latLng,
draggable: false,
map: map,
icon: {url:'/assets/icon_red.png'}
});
markers.push(marker1);
makeDiv(1, 15, 'Marker #');
google.maps.event.addListener(markers[1], 'click', function(e) {
infowindow.setContent('Marker postion: ' + this.getPosition());
infowindow.open(map, this);});
var latLng = new google.maps.LatLng(52.04062, -0.75942)
marker6 = new MarkerWithLabel({
position: latLng,
draggable: false,
map: map,
icon: {url:'/assets/icon_red.png'}
});
markers.push(marker6);
makeDiv(6, 15, 'Marker #');
google.maps.event.addListener(markers[6], 'click', function(e) {
infowindow.setContent('Marker postion: ' + this.getPosition());
infowindow.open(map, this);});
ETC
var titles = "";
;
;
;
;
;
;
;
;
;
你能添加生成的JS? – duncan
更新了我的答案 – user1738017