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.

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; 
  • 3
    declare an array var infowindow = [] ; ....... then use push ..... happy end - Alexey Shimansky
  • @ Alexey Shimansky Thanks for the hint, but if you can leave a more detailed answer - elik

1 answer 1

 var ArrayInfoWindows = []; var locations = []; // Должен быть заполнен function init(locati,map,marker){ for (var i =0;i++;i<maxWindow){ ArrayInfoWindows[i]=new google.maps.InfoWindow(); ArrayInfoWindows[i].setContent(locations[i][0]); ArrayInfoWindows[i].open(map, marker); } } init(23,2,2); // Создали 23 Новых окна /** OR **/ var ArrayInfoWindows = []; function add(locations,map,marker){ var Test = new google.maps.InfoWindow(); for (var i=0;i++;i<locations.length){ Test.setContent(locations[i][0]);//Не уверен насчет этого ArrayInfoWindows.push(Test); ArrayInfoWindows[ArrayInfoWindows.length-1].open(map, marker[i]); } } add(locations,Map,Marker); 
  • Will it be displayed right away without a click event? - elik
  • Well, yes (only map, marker will always be the same) - BigTows
  • no actually marker [i] - elik
  • he, too, proganyatsya in the cycle - elik
  • @elik I added option 2, I just don’t represent the structure of location and marker - BigTows