使用 FS 查询创建标记

Creating Markers with FSCollection

本文关键字:创建 查询 FS 使用      更新时间:2023-09-26

所以当一个新文档像这样插入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.push(marker); 它的执行,这很好,但现在我试图这样做

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

});

但是不起作用,所以我试图看看我的标记数组是什么样子的,所以做这个其他函数;

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

}

并像这样调用该数组标记函数;

[markers].forEach(arrayMarkers);

并获取此控制台.log;

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

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

我有 2 个标记,所以当我单击 1 个标记时,它会完美地缩放,但是当我单击第二个标记时,它会变成第一个标记

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

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

如果我使用

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

我明白了

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

通过创建此函数完成

  //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);
}});
} 

并在标记之前调用它.push

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