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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T06:51:20+00:00 2026-05-30T06:51:20+00:00

I’m trying to write a function for Google Maps API v3. Basically, I’m looping

  • 0

I’m trying to write a function for Google Maps API v3. Basically, I’m looping through all polygon points for a given shape and add them to a database by passing each point to a PHP function which inserts the data into MySQL.

    function saveSite() {

        // Create an array to hold the individual point saving results
        var submission_Result = [];
        var final_result = true;

        // Get the general properties for this shape
        var shape_ID = selectedShape.ID;
        var shape_Name = document.getElementById("info_name").value;
        var shape_Description = document.getElementById("info_description").value;
        var shape_Type = shapesArray[shape_ID].type;    

        var shape_Points = selectedShape.getPath();

        // Run through all points in the shape and save them
        for (var i = 0; i < shape_Points.length; i++) {
            var curPoint = shape_Points.getAt(i);

            // Prepare the point data to be saved
            var url = pageDir + "phpsqlinfo_addShapeData.php?db=" + database + "&job=" + jobnumber +
                      "&stype=" + shape_Type + "&snumber=" + shape_ID + "&sname=" + encodeURIComponent(shape_Name) + 
                      "&sdesc=" + encodeURIComponent(shape_Description) + "&sseqno=" + i + "&slat=" + curPoint.lat() + "&slng=" + curPoint.lng();

            // Attempt to save the shape data
            downloadUrl(url, function(data, responseCode) {
                if (responseCode == 200 && data.length <= 1) {
                    submission_Result.push(true);
                } else {
                    submission_Result.push(false);
                }
            });
        }

        // Run through all point results and confirm correct submission of points
        for (var i = 0; i < submission_Result.length; i++) {
            if (submission_Result[i] == false) {
                final_result = false;
            }                
        }

        // If all points were successfully saved, tell the user
        if (final_result == true) {
            // All points saved successfully so do something
        } else {
            // Something went wrong and not all points were added so do something else               
        }
    }

I know that the *downloadURL*runs as an asynchronous function and thus i can’t currently loop through the *submission_result* array and check whether all points were added correctly.
My question is, is there any way i can wait for all of the asynchronous calls to finished and then check the result array?

Maybe something like this for example?:

                        });
        }

        while (submission_Result.length < shape_Points.length) {
            // Do something wait a short while
        };

        // Run through all point results and confirm correct submission of points
        for (var i = 0; i < submission_Result.length; i++) {

Any ideas would be greatly appreciated as I’m totally stumped!

Thanks in advance.

  • 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-30T06:51:21+00:00Added an answer on May 30, 2026 at 6:51 am

    You have to check this in the callbacks passed downloadUrl, e.g.:

    downloadUrl(url, function(data, responseCode) {
       //...
    
       if (submission_Result.length === shape_Points.length)
          allResultsReady();
    });
    

    If all results are in, the function allResultsReady will be called.

    Using a loop would block the entire browser window which is definitely not what you want.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
Basically, what I'm trying to create is a page of div tags, each has
I am trying to loop through a bunch of documents I have to put
I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I need a function that will clean a strings' special characters. I do NOT
I want to construct a data frame in an Rcpp function, but when I

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.