【问题标题】:Creating Markers with FSCollection使用 FSCollection 创建标记
【发布时间】:2014-12-24 05:25:14
【问题描述】:

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

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

});

但不工作,所以我想看看我的 ma​​rkers 数组是什么样子的,所以制作另一个函数;

     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 个标记时,它会完美缩放,但是当我单击第二个标记时,它会很快到达第一个标记

这就是我的 ma​​rkers 数组的样子; [开,开]> 0:开 1:开

如果我在数组上嵌套数组

如果我使用

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

我知道了

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

【问题讨论】:

    标签: javascript arrays google-maps foreach meteor


    【解决方案1】:

    通过创建此函数完成

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-01-09
      • 1970-01-01
      • 1970-01-01
      • 2019-06-10
      • 2018-12-08
      • 2015-02-28
      • 2013-06-17
      • 1970-01-01
      相关资源
      最近更新 更多