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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T08:16:43+00:00 2026-05-18T08:16:43+00:00

Is there any other way to do this that might prevent the setTimeout to

  • 0

Is there any other way to do this that might prevent the setTimeout to be necessary?

function initialize(){

   $.get('test.xml', function(xml){

      //do some stuff with xml like...
      var icons = xml.documentElement.getElementsByTagName("icon");
        for(var i = 0; i < icons.length; i++) {
           var iconImage = icons[i].getAttribute("image"),
        }

      //do more things to create markers like...
      markers.push(marker);

      //try to add markers to map
      //this will give an error
      addMarkers(markers);

      //setTimeout makes it work
      setTimeout("addMarkers(markers)", 300);

      //is there any way to avoid the timeout?
   });

}
  • 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-18T08:16:43+00:00Added an answer on May 18, 2026 at 8:16 am

    It is hard to tell what is wrong, since you aren’t providing the error you get or the code that creates the marker. Trying to guess, the most probably thing happening is that the code you run to create the markers and perhaps to initialize the map doesn’t run synchronously, but asynchronously. This will be definitely the case if there are some ajax calls involved and it means that the map/manager system aren’t ready by the time the last javascript line is called, but after some period of time and by sure after the function has exited.

    In order to avoid the setTimeout, which among others will introduce an unnecessary delay and is very easy to break, should more time is needed in certain conditions, you need to look at the code that creates the markers and see if there is a callback/event defined, which marks the completion of the initialization procedure.

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

Sidebar

Related Questions

Besides the DateTime ctor (new DateTime(year, month, day)) , is there any other way
Is there any way other than using reflection to access the members of a
Is there a web service of some sort (or any other way) to pull
Is there any way in the SQL language or in MySQL (or other DBMA)
Is there a way to have TortoiseSVN (or any other tool) auto-add any new
Is there any other place besides the metabase.xml file where the file upload size
EDIT: Is there any other phone systems that allow connecting into the native messaging
Is there any way to prevent a click from an <a> triggering delegated click
Are there any other ways to avoid LazyInitializationExceptions in a Hibernate web application besides
Are there any other IDEs worth my time for Lotus Notes development? We're doing

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.