There is an interval in which the elements of the array are displayed on the map. I want to add information to the displayed markers. But for some reason the method does not work. I expand the array through the loop ... But nothing happens

var Cicle = setInterval(function() { var locations = [ ['Bondi Beach', -33.890542, 151.274856, 4], ['Coogee Beach', -33.923036, 151.259052, 5], ['Cronulla Beach', -34.028249, 151.157507, 3], ['Manly Beach', -33.80010128657071, 151.28747820854187, 2], ['Maroubra Beach', -33.950198, 151.259302, 1] ]; var markers = []; var infowindow = []; var num_markers = locations.length; for (var i = 0; i < num_markers; i++) { markers[i] = new google.maps.Marker({ position: { lat: locations[i][1], lng: locations[i][2] }, map: map }); }; for (var i = 0; i < num_markers.length; i++) { markers[i].setPosition(locations[i][1], locations[i][2]); //Данный метод добавения окна с текстом не работает* infowindow[i] = new google.maps.InfoWindow(); infowindow[i].setContent(locations[i][0]); infowindow[i].open(map, marker[i]); } }, 15000); Cicle; 

    2 answers 2

    InfoWindow does not need to be created several times.
    Exactly the same question was created on en stackoverflow.
    Multiple “InfoWindow” for array of “markers” on Google Maps?
    Googled in a minute.

    Before asking a question, it is better to spend a minute on Google, this is faster.

    • Thank you. I actually found the solution myself, but it is not a good one ... - elik

    I was able to make BUT, he adds a window in a circle from which the application begins to drag on ... To the campaign The only solution is only through the event of the listener and here is my decision

     var infowindow = []; infowindow[i]=new google.maps.InfoWindow(); infowindow[i].setContent(locations[i][0]); infowindow[i].open(map,markers[i]);