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

  • SEARCH
  • Home
  • 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 9206879
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T00:16:07+00:00 2026-06-18T00:16:07+00:00

Can somebody please explain why my Google Maps info windows are only opening at

  • 0

Can somebody please explain why my Google Maps info windows are only opening at the bottom left marker?
See here for the fiddle http://jsfiddle.net/Vj3nw/7/

When I click on any of the markers, only the bottom-left one is opened. I would like the marker that is clicked to open.

I believe the problem is due to the loop below, and this question seems to have the same problem Setting onclick to use current value of variable in loop

“The problem you were hitting is that javascript doesn’t use block scope. Instead all variables have a lifetime of their containing function. So there was only ever one a captured in all of the onclick functions and they all see it’s final value.”

I just can’t quite translate that solution to mine.

Many thanks.

for (var i = 0; i < 4; i++) {
    var marker = new google.maps.Marker({
        position: flightPlanCoordinates[i],
        icon: Symbol,
        map: map
    });

    infowindow = new google.maps.InfoWindow();
    infowindow.setContent("hello");

    google.maps.event.addListener(marker, 'click', function () {
        infowindow.open(map, marker);
    });

}
  • 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-06-18T00:16:08+00:00Added an answer on June 18, 2026 at 12:16 am

    Generating your markers and adding the listeners in their own function, called from the loop like the updated fiddle works.

    function create_marker(i,flightPlanCoordinates,Symbol,map){
            var marker = new google.maps.Marker({
                position: flightPlanCoordinates[i],
                icon: Symbol,
                map: map
            });
    
            infowindow = new google.maps.InfoWindow();
            infowindow.setContent("hello" + i);
    
            google.maps.event.addListener(marker, 'click', function() {
                infowindow.open(map,marker);
            });
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi can somebody please explain what are the URL's that we can see at
Can somebody please explain me what is celery Application object, noted here and what
Can somebody please explain how to use macros in x86 assembly coding
Can somebody please explain how to find out if full text search is enabled
Can somebody please explain to me the meaning of this line of code? val
Can somebody please explain to me the difference between: Session.Add(name,txtName.text); and Session[name] = txtName.text;
Can somebody please tell me how I can get google analytics on every page
I'm beginner in programming. Can somebody please explain (by simple words) what do I
Can somebody please explain with examples (of code) what is the difference between deadlock
Can somebody please explain what does this warning mean: undefined reference to 'WinMain@16' ?

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.