Javascript 如何向多个google地图标记添加单独的信息窗口

Javascript 如何向多个google地图标记添加单独的信息窗口,javascript,google-maps,google-maps-api-3,Javascript,Google Maps,Google Maps Api 3,我试图在手机应用程序中为多个地图标记添加单独的信息窗口,但没有多大成功。当我运行应用程序并单击任何标记时,同一标记每次都会打开其信息窗口。不知道我哪里出错了 result.users.forEach(function(entry){ latLng = new google.maps.LatLng(entry.user_lat, entry.user_lon); marker.push(new google.m

我试图在手机应用程序中为多个地图标记添加单独的信息窗口,但没有多大成功。当我运行应用程序并单击任何标记时,同一标记每次都会打开其信息窗口。不知道我哪里出错了

            result.users.forEach(function(entry){
                latLng = new google.maps.LatLng(entry.user_lat, entry.user_lon);
                marker.push(new google.maps.Marker({map: map, position: latLng}));
                circle.push(new google.maps.Circle({map: map, radius: entry.user_accuracy, strokeWeight:1, strokeOpacity:0.5, fillOpacity:0.2, fillColor: '#AA0000'}));
                circle[circle.length-1].bindTo('center', marker[marker.length-1], 'position');
                info.push(new google.maps.InfoWindow({content: '<b>Phone ID:</b> ' + entry.user_uuid + '<br /><b>Callsign:</b> ' + entry.user_callsign + '<br /><b>Time:</b> ' + entry.user_datestamp}));
                google.maps.event.addListener(marker[marker.length-1], 'click', function() {info[info.length-1].open(map, marker[marker.length-1]);});
                if (entry.user_uuid == device.uuid){
                    map.setCenter(latLng);
                }
            });
result.users.forEach(函数(条目){
latLng=新的google.maps.latLng(entry.user\u lat,entry.user\u lon);
marker.push(新的google.maps.marker({map:map,position:latLng}));
circle.push(新的google.maps.circle({map:map,radius:entry.user_精度,strokeWeight:1,strokeOpacity:0.5,fillOpacity:0.2,fillColor:'#AA0000'));
圆[circle.length-1].bindTo('center',marker[marker.length-1],'position');
info.push(新的google.maps.InfoWindow({content:'Phone ID:'+entry.user_uuid+'
Callsign:'+entry.user_Callsign+'
时间:'+entry.user_datestamp})); google.maps.event.addListener(marker[marker.length-1],'click',function(){info[info.length-1].open(map,marker[marker.length-1]);}); if(entry.user_uuid==device.uuid){ 地图设置中心(latLng); } });
打开信息窗口时,必须更新其内容,否则将显示最后一个内容

只需修改addListener:

google.maps.event.addListener(marker, 'click', function () {
    info.setOptions({
        content: MarkerContent
    });
    info.open(map, marker);
}); 
可能的重复可能的重复