因此,当新文档插入到 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集合上创建一些文档时,都会插入一个标记,所以也有这个标记数组,所以每次都有一个新的标记已创建 markers.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);
}});
}
并在markers.push之前调用它
myInfoWindow(marker2,map,nombreCliente,telefonoCliente,ubicacionCliente,facebookCliente);
关于javascript - 使用 FSCollection 创建标记,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27103382/