InfoWindow is always the same in the markers all (javascript)

2

I'm creating the markers as follows:

 var contentString = '<div id="content">' +
                    '<div id="siteNotice">' +
                    '</div>' +
                    '<h1 id="firstHeading" class="firstHeading">teste3.1.1.1</h1>' +
                    '<div id="bodyContent">' +
                    '<p><b>Morada:</b>teste3.1.1' +
                    '<p><b>Horário:</b>teste3.1' +
                    '</div>' +
                '</div>';

                var infowindow = new google.maps.InfoWindow({
                    content: contentString
                });

                var marker = new google.maps.Marker({
                    position: PointA,
                    map: map,
                    icon: iconBase,
                    title: 'Teste3'
                });
                markers.push(marker);

                marker.addListener('click', function () {
                    infowindow.open(map, marker);
                });

                var contentString_ = '<div id="content">' +
                    '<div id="siteNotice">' +
                    '</div>' +
                    '<h1 id="firstHeading" class="firstHeading">teste2</h1>' +
                    '<div id="bodyContent">' +
                    '<p><b>Morada:</b>teste2.1' +
                    '<p><b>Horário:</b>Teste2.1.1' +
                    '</div>' +
                '</div>';

                var infowindow_ = new google.maps.InfoWindow({
                    content: contentString_
                });

                var marker3 = new google.maps.Marker({
                    position: pointB,
                    map: map,
                    icon: iconBase,
                    title: 'Teste 2'
                });
                markers.push(marker3);

                marker3.addListener('click', function () {
                    infowindow_.open(map, marker3);
                });

                var contentString2 = '<div id="content">' +
                    '<div id="siteNotice">' +
                    '</div>' +
                    '<h1 id="firstHeading" class="firstHeading">teste1</h1>' +
                    '<div id="bodyContent">' +
                    '<p><b>Morada:</b>teste1.1' +
                    '<p><b>Horário:</b>Dias' +
                    '</div>' +
                '</div>';

                var infowindow2 = new google.maps.InfoWindow({
                    content: contentString2
                });

                var marker2 = new google.maps.Marker({
                    position: pointC,
                    map: map,
                    icon: iconBase,
                    title: 'Teste'
                });
                markers.push(marker2);

                marker2.addListener('click', function () {
                    infowindow2.open(map, marker2);
                });

On the site when I step over the Marker and click it it always shows the same infowindow always with the same information can someone tell me why?

    
asked by anonymous 20.05.2016 / 16:49

1 answer

0

Hello, I ran a test using your code, just setting coordinates and it worked:

link

But the ideal thing is that information from markers and their respective infoWindows are in an array, which you then access with a loop: link

    
01.11.2016 / 18:51