creating markers in loop - Infowindow does not open when inside an click Listener

后端 未结 2 1301
被撕碎了的回忆
被撕碎了的回忆 2021-01-23 02:25

i have a google map with multiple markers and each has its own infowindow.

nothing happens when i click. fyi: i know it the listener fires because i did put a alert in

2条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-23 02:43

    I have the same issue and it has got something to do with the loop, because when I use hard coded values like this they do work:

                    // Add infowindow
                    google.maps.event.addListener(markers[0], 'click', function() {
                      infowindows[0].open(map,markers[0]);
                    });
                    // Add infowindow
                    google.maps.event.addListener(markers[1], 'click', function() {
                      infowindows[1].open(map,markers[1]);
                    });
    

提交回复
热议问题