2014-11-24 30 views
0

所以我創建標記,當這樣一個新文檔插入FSCollection上。創建標記與FSCollection

我有這個發現變量。

cordenadasClientes = Clientes.find({}, {fields:{'metadata.latCliente': 1,'metadata.longCliente': 

遵循這個eachFunction。

var count = 0, 
markers = [], 
marker; 
    cordenadasClientes.forEach(function(){ 
    var latitudCliente = cordenadasClientes[count].metadata.latCliente; 
    var longitudCliente = cordenadasClientes[count].metadata.longCliente; 
    var nombreCliente = cordenadasClientes[count].metadata.nombreCliente; 
    marker = new google.maps.Marker({ 
     position: new google.maps.LatLng(latitudCliente ,longitudCliente), 
     map: map, 
     title: nombreCliente, 
     icon :'http://maps.google.com/mapfiles/marker_yellow.png', 
     }) 
    count++; 
    markers.push(marker); 
    }) 

及其工作相當發現,每次我上Clientes創建一些文件收集時間,插入的標記的,所以也有這個標記陣列,所以每次一個新標誌其創建標記。推(標記);它的執行,並且那woork不錯的,但我現在想這樣做

google.maps.event.addListener(markers, 'click', function() { 
map.setZoom(8); 

});

但不工作,所以即時通訊設法看看我的標記數組看起來像這樣使其他功能;

 function arrayMarkers(element,index,array){ 
    console.log(markers); 

}

並調用arrayMarkers功能這樣;

[markers].forEach(arrayMarkers); 

並獲取此Console.log;

im the index : 0 and the object [object Object],[object Object] 

所以我想創建標記sotring一個陣列上,並使用一個事件監聽標誌,什麼即時做錯了?好像很喜歡後事件偵聽器只是1個標記

例如 工作我有2個標記,所以當我點擊1標記時它的縮放非常完美,但是當我點擊第二個標記時它的標記爲第一個標記

這是我的標記數組的外觀; [開,開]> 0: 1:

一樣,如果數組

和如果我使用

function arrayMarkers(element,index,array){ 
     console.log(array); 
} 

我得到這個

[Array[2]] 
> 
0: Array[2] 
> 
0: On 
1: On 
上IM嵌套陣列

回答

2

完成通過創建此功能

//Added nombreCliente as parameter 
    function  myInfoWindow(marker2,map,nombreCliente,telefonoCliente,ubicacionCliente,facebookCliente){ 
var infoWindow = new google.maps.InfoWindow(); 

google.maps.event.addListener(marker2, 'click', function() { 
for(var i=0;i<cordenadasClientes.length;i++){ 
    infoWindow.setContent("Informacion Cliente : <br/>" + "Dale Pa: " + nombreCliente + "<br/> Telefononos: " + telefonoCliente + "<br/> Ubicado en: " + ubicacionCliente + "<br/> No olvides Pasarte Pa' su Facebook: ' " + '<a href="#' + facebookCliente + '">'); 
infoWindow.open(map, marker2); 
}}); 
} 

,並調用它之前markers.push

myInfoWindow(marker2,map,nombreCliente,telefonoCliente,ubicacionCliente,facebookCliente);