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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T22:45:42+00:00 2026-06-17T22:45:42+00:00

I have a function LoadXML() in which after a ajax call to the server

  • 0

I have a function LoadXML() in which after a ajax call to the server I’ve got an array with 100 addresses type string;

Also here we call the function extractAddressed()with the function addmarkers as callback;

function loadXMLDoc(l)
    {    
      //making ajax call to the server to get the addresses

    arrayMyAddresses.push(rec[i][8] + "," + rec[i][10]);

    extractAddresses(addmarkerss);

    }

Here is extractAddresses function which send a part of the addresses which i want to geocode using the getLocations method which performs asynchronous call to the google servers

function extractAddresses(callback)
    {    alert (startman);
          i=startman;

        while  (i<startman+intPageSize)
        {
            geocoder = new GClientGeocoder();
            //alert(arrayMyAddresses[i]);
            geocoder.getLocations(arrayMyAddresses[i], addAddressToMap);
            i++;

        }

        //callback();
        setTimeout(callback,300);


    }

Here you may also see the function addAddresstoMap which handle the response from google servers and creates an array of gmarkers!

function addAddressToMap(response) 
    {

        if (!response || response.Status.code != 200) 

        {
           alert("Sorry, we were unable to geocode that address");
        } 

        else 
        {   

            place = response.Placemark[0];
            point = new GLatLng(place.Point.coordinates[1], place.Point.coordinates[0]);
            var marker = new GMarker(point);
            batch.push(marker);
            //alert ("batchaddaddresstomap " + batch.length);

        } 


    }           

And at last addmarkerss() function which add the array of Gmarkers to the map;

function addmarkerss()
    {

        // alert("batchf: " + batch.length);         
         mgr = new MarkerManager(map);
         mgr.addMarkers(batch,13);
         mgr.refresh();

    }

So this is how the programme should work
when i call extractAddresses and i give one by one the addresses for geocoding to addAddresstoMap function and they are dynamically added to an array of type Gmarker;
when I’m ready with this i call addmarkers() to put the markers on my map;

But what does it make actually

when i call extractaddresses it somehow goes first to addmarkers function it sees that banch array is empty and it doesn’t load any markers;
When i put setTimeout(callback,300);and i postpone the execution of addmarkers everything works.


What may be the reason. And i also want to ask if the problem is here:
Although it is true that a callback function will execute last if it is placed last in the function, this will not always appear to happen. For example, if the function included some kind of asynchronous execution (*like an Ajax call as it’s my case
), then the callback would execute after the asynchronous action begins, but possibly before it finishes. is it my case? also how can i solve my problem without settimeout*

  • 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-17T22:45:43+00:00Added an answer on June 17, 2026 at 10:45 pm

    If the function included some kind of asynchronous execution (like an Ajax call as it’s my case), then the callback would execute after the asynchronous action begins, but possibly before it finishes. is it my case?

    It is the case, geocoding is an asynchronous process.

    You must call addmarkerss() inside addAddressToMap() when batch reaches the expected length(the last geocoding-request has been finished)

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

Sidebar

Related Questions

I have function some_func_1 which will create an object of type some_type and will
Inside my Controller i have function that runs after user clicks on item, which
I have function: char *zap(char *ar) { char pie[100] = INSERT INTO test (nazwa,
I have function getCartItems in cart.js and I want to call that function in
i have function to send mail with attachment to microsoft exchange server. My problem
I have a web service which returns something of type MyData . public class
I have function along these lines: public void view(string msg) { messagebox.show(msg); } .
I have a function where I am passing a string as params called filterXML
I have a really annoying problem. I got this bunch of code which runs
I have a function which uses MSXML to post an XML document which yesterday

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.