使用FSCollection创建标记

时间:2014-11-24 11:06:32

标签: javascript arrays google-maps foreach meteor

所以当我在FSCollection上插入新文档时,我会创建标记。

我有这个发现变量。

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

关注每个功能。

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 Collection上创建一些文档时,插入一个标记,所以也有这个 markers array ,所以每次都是新的标记它创建的 markers.push(marker); 它的执行,那就好了,但现在我试图这样做

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

});

但是没有用,所以我试着看看我的 marker 数组是怎么样的,所以要做另一个函数;

     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]

所以我想在数组上创建标记并在eventListener上使用这些标记后,我做错了什么?似乎喜欢事件监听器只对1标记工作

示例 我有2个标记,所以当我点击1个标记时它完全放大,但当我点击第二个标记时它的第一个标记

这是我的标记数组的外观; [On,On]> 0:开 1:开启

就像我在数组上嵌套数组一样

如果我使用

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

我得到了这个

[Array[2]]
>
0: Array[2]
>
0: On
1: On

1 个答案:

答案 0 :(得分: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);