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 9012719
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T03:04:38+00:00 2026-06-16T03:04:38+00:00

I understand why it doesn’ work. But have no idea how to get result:

  • 0

I understand why it doesn’ work. But have no idea how to get result:

There is a global array:

var members=[[1,x,y,z],[2,x1,y1,z1],[3,x2,y2,z3]];

function drop() {
  for (var i = 0; i < members.length-1; i++) { 
    setTimeout(function() {
      addMarker();
    }, i * 30);
  }
}

function addMarker() { 
  var marker = new google.maps.Marker({
    position: members[iterator][1],
    icon: pinImage[members[iterator][2]],
    shadow: shadow,
    map: map,
    draggable: false,
    title: members[iterator][3],
    animation: google.maps.Animation.DROP    }); 
  google.maps.event.addListener(marker, 'click', function() {
    $.ajax({
      url : 'ajax/get_infowindow_content.php?id='+members[iterator][0],
      success: function(data) {
        infowindow.close();
        infowindow.setContent(data);
        infowindow.open(map, marker);
      }
    });
  }); 
  markers.push(marker);  
  iterator++;
}

The problem is here:

url : 'ajax/get_infowindow_content.php?id='+members[iterator][0],

when i click the marker, it fires the function and checks the members[iterator][0] but the iterator is the last value of iterator (after the whole loop).

The best solution would be some kind of .value() like:

url : 'ajax/get_infowindow_content.php?id='+members[iterator][0].value(),

but of course it doesn’t work.

I’m stacked..

  • 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-16T03:04:40+00:00Added an answer on June 16, 2026 at 3:04 am

    You just need a closure and to pass a parameter to the addMarker function :

    var members = [[1, x, y, z], [2, x1, y1, z1], [3, x2, y2, z3]];
    
    function drop() {
        for (var i = 0; i < members.length; i++) {
            (function(j) {
                setTimeout(function() {
                    addMarker(members[j]); //pass the value
                }, i * 30);
            })(i); //closure to keep the value
        }
    }
    
    function addMarker(member) {
        var marker = new google.maps.Marker({
            position: member[1],
            icon: pinImage[member[2]],
            shadow: shadow,
            map: map,
            draggable: false,
            title: member[3],
            animation: google.maps.Animation.DROP
        });
        google.maps.event.addListener(marker, 'click', function() {
            $.ajax({
                url: 'ajax/get_infowindow_content.php?id=' + member[0],
                success: function(data) {
                    infowindow.close();
                    infowindow.setContent(data);
                    infowindow.open(map, marker);
                }
            });
        });
        markers.push(marker);
    }​
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I understand that Javascript doesn't have multiple threads, but I'd like to know if
I cannot understand why it doesn't work now. I write: $(function() { $('a').click(function(){ $('div#box').animate({
I can't understand why this doesn't work, or what I need to get it
I don't understand why this doesn't work. Explanation will be appreciated. var scrollTop =
I don't understand why livequery doesn't bind the event, but I have to use
I'm sorry, but I can't understand why this doesn't work. After compile, I receive
I don't understand why this doesn't work. I have a div with an iframe
Here is the script, I don't understand why it doesn't work... function FirstFactorial(num) {
I'm trying to load a UIWebView , but I can't understand why doesn't work,
I'm using this simple node.js code example but I don't understand why FireBug doesn't

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.