Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6885687
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T05:39:56+00:00 2026-05-27T05:39:56+00:00

i have a google map with multiple markers and each has its own infowindow.

  • 0

i have a google map with multiple markers and each has its own infowindow.

nothing happens when i click. fyi: i know it the listener fires because i did put a alert in ther before and it worked.

Problem Code is:

google.maps.event.addListener(point[i], 'click', function() {
     infowindow[i] = new google.maps.InfoWindow({content: contentString[i] });
     infowindow[i].open(map,point[i]);
});

if i only do

     infowindow[i] = new google.maps.InfoWindow({content: contentString[i] });
     infowindow[i].open(map,point[i]);

it works. but not in my addListener function. i guess ther is something that googlemaps doesnt like but firebug gives me 0 errors..

really need your help. Thanks a lot!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T05:39:57+00:00Added an answer on May 27, 2026 at 5:39 am

    It is because you probably have closure within loop! So the variable i in callback is already overwritten at the time when the callback is called. You have two options how to fix it:

    1) classical “closure in loop” workaround (you do another closure for every loop iteration):

    for (i = 0; i < 20; i++) { (function  (i) {
        google.maps.event.addListener(point[i], 'click', function() {
             infowindow[i] = new google.maps.InfoWindow({content: contentString[i] });
             infowindow[i].open(map,point[i]);
        });
    })(i);
    }
    

    2) avoid closure and use the marker data structure:

    for (i = 0; i < 20; i++) {
        point[i].i = i;
        google.maps.event.addListener(point[i], 'click', function() {
             this.myinfowindow = new google.maps.InfoWindow({content: contentString[this.i] });
             this.myinfowindow.open(map, this);
        });
    }
    

    (or you could also move the contentString also to the marker: point[i].contentString = ... and use this.contentString in the click handler. Then you don’t need the point[i].i attribute.)

    Personally I much more prefer the 2nd solution over the first, since the closures consume memory etc.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to display multiple markers on a map, each with their own infowindow.
I currently have a Google map that geocodes multiple markers on the fly but
I have a map with multiple markers, which I populate via an array. Each
I'm trying to add infoWindow's to multiple markers on a Google Map. The closest
I have a map with multiple markers of companies using google maps API v3.
I have found a code to show Google maps with multiple markers using JQuery
I understand that if I have multiple markers on a map, and I need
I am working on a google Map Api using fusion. I have multiple search
I have created a map which allows the user to plot multiple markers with
Hi I have this weird problem with Google Maps V3 API. Showing multiple markers

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.