Google maps infowindow showing on wrong marker

后端 未结 5 558
失恋的感觉
失恋的感觉 2020-12-30 02:40

I have a piece of javascript code where I create markers and attach InfoWindows to them, like this:

for (var i = 0; i < 8; i++) {
    var marker = new goo         


        
5条回答
  •  感情败类
    2020-12-30 03:03

    Try this:

            // Create a marker for each place.
             marker = new google.maps.Marker({
                 map: map,
                 icon: icon,
                 title: place.name,
                 animation: google.maps.Animation.DROP,
                 position: place.geometry.location
             });
             var infowindow = new google.maps.InfoWindow({
             content:'
    ' + place.name + '
    ' + 'Place ID: ' + place.place_id + '
    ' + place.formatted_address + '
    ' }); marker.addListener('click', function() { infowindow.open(map, this); });

    Thank you

提交回复
热议问题