Nithin Dev
Nithin Dev

Reputation: 421

How to add multiple markers and infowindow using Javascript

I am using Google map API V3 to draw routes. I am having 'LatLng' array and I am looping this array to plot route on map.and I also need to add markers and infowindow for each address. I am getting markers on the map, But info window dose not work, Here is my Code.

for(i=0;i<s[0].length;i++)
{
marker[count] = new google.maps.Marker({
                    position: s[0][i]["location"],
                    map: map
                });



marker[count].info = new google.maps.InfoWindow({
          content: '<b>Speed:</b> '
        });

 google.maps.event.addListener(marker[count], 'click', function() 
  {
     marker[count].info.open(map, marker[count]);
  });

count++;

}

Upvotes: 0

Views: 626

Answers (1)

user1931858
user1931858

Reputation: 10656

Instead of

marker[count].info.open(map, marker[count]);

You may

this.info.open(map, this);

Here is a tutorial on multiple makers with infowindow.

Upvotes: 1

Related Questions