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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T04:52:13+00:00 2026-06-08T04:52:13+00:00

I know there’s a question about this Google Maps API v3 drop markers from

  • 0

I know there’s a question about this Google Maps API v3 drop markers from XML with delay? and I followed it, but I had to made a mistake in my code, here it is:

function dropAnim(lat,lng,name) {

    console.log("---- " + lat + " - " + lng);

    var marker = new google.maps.Marker({

        position: new google.maps.LatLng(lat,lng),
        map: map,
        title: name,
        animation: google.maps.Animation.DROP,
        icon: imageCar,

    });

}

var counter = 0;

$.get('http://server.com/methods.php?m=loadPins', function(data) {

dataName = data.name.split(";");
dataLat = data.lat.split(";");
dataLng = data.lng.split(";");

dataLength = dataName.length-1;

for(var i=0;i<dataLength;i++) {

   var lat = dataLat[i];
   var lng = dataLng[i];

   console.log(lat + " - " + lng);

   setTimeout(function() {
      dropAnim(lat,lng,dataName[i]);
   }, counter * 400);

   counter++;
} 

},"json");

The problem is that it loads 3 pins in the exact same place. dataLat and dataLng load 3x times different and I can see that in console, but when I see what comes out in console from insde the function, there are 3 same lat and lng (the last one).

  • 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-08T04:52:15+00:00Added an answer on June 8, 2026 at 4:52 am

    Try like this:

     setTimeout((function(i) {
         return function(){
            dropAnim(dataLat[i],dataLng[i],dataName[i]);
         };
     })(i), counter * 400);
    

    Your problem was, when your timeout’s callback is called, i variable already has dataLength value, as your loop is already finished by that time.

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

Sidebar

Related Questions

I know there are many threads about calculating from lat/long to metric systems. This
I know there are ways of installing SQL Express from the command line. This
I know there are dozens of questions that ask about this error, but none
I know there are duplicates of this question, and the answer was to refactor
I know there are several question like this one but I feel I've spent
I know there are lots of stack overflow posts about this. I have this
I know there are many posts about this issue however I cannot find one
I know there are a lot of threads talking about this and believe me
I know there are several topics out there about this, but none of them
I know there are many questions about this but none of them helped my

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.