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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T16:52:31+00:00 2026-05-22T16:52:31+00:00

I believe that I have having a timing issue with geocoder results. See a

  • 0

I believe that I have having a timing issue with geocoder results. See a snippet of code below.

I am basically performing a geocode and getting the result. I then pass the result to a server side method via the jQuery AJAX call. Finally the result of the method returns a JSON object. Based on the result I may or may not perform a second geocode. This is where the problem lies.

You can see I have a variable hasResult defaulted to false, and is toggled to true when a valid result has been determined. In all cases this works perfect, except when the need for a second geocode occurs. The geocode happens successfully and the code executes, but the final hasResult check still returns false. How can this be?

var hasResult = false;            
geocoder.geocode({ "address": address }, function (results, status) {
    if (status == google.maps.GeocoderStatus.OK) {
        $.ajax({
            url: "URL",
            type: "POST",
            dataType: "json",
            data: results
            contentType: "application/json; charset=utf-8",
            success: function (result) {
                        if (result.Valid) {
                            hasResult = false;
                            //Some other code, works perfect                            
                        } else {
                            geocoder.geocode({ "address": result.ValidRequest }, function (resultsNew, statusNew) {
                                if (statusNew == google.maps.GeocoderStatus.OK) {
                                    hasResult = false; 
                                    //Some other code, works perfect
                                }
                            });
                        }
                    });
                });
            }
        });
    }
});

if (hasResult == true) {
    alert('Success');
} else {
    alert('Fail');
}

Thanks

  • 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-22T16:52:32+00:00Added an answer on May 22, 2026 at 4:52 pm

    This is because you check the value of hasResult before you get the results from the server. This happens, because the request is asynchrounous. You should use callbacks instead.

    Edit:

    Try this (this is only a mockup and is not tested, change it to improve readability, pass successOrFailure as a parameter/callback etc.):

    var hasResult = false;            
    
    var successOrFailure = function(hasResult){
        if (hasResult == true) {
            alert('Success');
        } else {
            alert('Fail');
        }
    };
    
    geocoder.geocode({ "address": address }, function (results, status) {
        if (status == google.maps.GeocoderStatus.OK) {
            $.ajax({
                url: "URL",
                type: "POST",
                dataType: "json",
                data: results
                contentType: "application/json; charset=utf-8",
                success: function (result) {
                            if (result.Valid) {
                                hasResult = false;
                                successOrFailure(hasResult);
                                //Some other code, works perfect                            
                            } else {
                                geocoder.geocode({ "address": result.ValidRequest }, function (resultsNew, statusNew) {
                                    if (statusNew == google.maps.GeocoderStatus.OK) {
                                        hasResult = false;
                                        successOrFailure(hasResult); 
                                        //Some other code, works perfect
                                    }
                                });
                            }
                        });
                    });
                }
            });
        }
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I believe I have a potential threading issue. I have a user control that
I can't believe that I'm having an issue with this. My setTimeout is: setTimeout(function(){showContent(entries,
I believe that I have successfully impersonated my own user account while running an
I have been lead to believe that it is possible to pass a class
I have a Spring application that I believe has some bottlenecks, so I'd like
I strongly believe that, reading code and reading good code is key to great
I don't like constructor based dependency injection. I believe that it increases code complexity
I believe that I am having a bad database design and need some help
We have been having this issue pop up sporadically, but now I can reproduce
I read that having CC 10 or less would be highly maintainable code. But

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.