javascript - 使用 FSCollection 创建标记

标签 javascript arrays google-maps foreach meteor

因此,当新文档插入到 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集合上创建一些文档时,都会插入一个标记,所以也有这个标记数组,所以每次都有一个新的标记已创建 ma​​rkers.push(marker); 执行,这很好,但现在我正在尝试这样做

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]

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

示例 我有 2 个标记,因此当我单击 1 个标记时,它的缩放效果非常好,但是当我单击第二个标记时,它很快就会缩放到第一个标记

这就是我的标记数组的样子; [开,开]> 0:开 1:开

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

如果我使用

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

并在ma​​rkers.push之前调用它

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

关于javascript - 使用 FSCollection 创建标记,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27103382/

相关文章:

javascript - Google 自动加载 map Adsense 库

javascript - 使用 css 表插入行/列

javascript - 停止播放任何当前音频

python - numpy 直方图 bool 索引与沿维度 0 的索引数组不匹配;维度是

python - 列出 1-50 范围内的 50 个随机数,使得相邻数字彼此不在 15 以内

javascript - 如何在 Google map 上显示 2 个标记?

javascript - 尽管给出了高度, Owl Carousel 仍不显示图像

javascript - 更新记录时缺少可选字段值的正确明确的服务器端行为应该是什么?

arrays - bash 中是否有一个 array_combine 函数,我可以在其中从两个函数创建一个关联数组?

javascript - 尝试使用 google api v3 从地址获取位置