Infowindow is always the same in all markers(javascript)

Asked

Viewed 154 times

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 on Marker and click it always shows the same infowindow always with the same information someone can tell me why?

1 answer

0

Browser other questions tagged

You are not signed in. Login or sign up in order to post.