How to set a popup on markers with Google Maps API?

后端 未结 4 439
小鲜肉
小鲜肉 2021-02-01 18:09

I have this code where I display and set all my markers. How can I add a popup with some information on markers with this code? I add \"i\" variable on text, but it sets on all

4条回答
  •  借酒劲吻你
    2021-02-01 18:52

    That's because the variable i is not used in the loop but when the marker is clicked -- and then i is equal to the last index + 1... The addListener is asynchronous, not synchronous.

    Remove infowindow.setContent('test: ' + i + ''); and replace content: " " with content: 'test: ' + i. This should fix your problem.

提交回复
热议问题