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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T22:59:44+00:00 2026-06-03T22:59:44+00:00

just wondering if someone can help me with a Javascript principle. I’m guessing this

  • 0

just wondering if someone can help me with a Javascript principle. I’m guessing this is pretty core if I want to pass a function as a parameter. I know a little about Javascript but I admit possibly not enough about its subtleties.

So, codeAddress is invoked, then my first alert (HERE2) is reached, code passes back to my showOnMap function, then my second alert (HERE3) is reached. Why does my HERE3 alert show before my HERE2 alert? Is there anything I can do to tell Javascript to wait?

Thanks in advance

function showOnMap() {
    var inputStart = document.getElementById('CurrentHitch_StartDescription').value;
    var inputEnd = document.getElementById('CurrentHitch_EndDescription').value;
    codeAddress(inputStart, true); //HERE1*************
    codeAddress(inputEnd, false);
    var bounds2 = new google.maps.LatLngBounds(this.markerStart.getPosition());
    bounds2.extend(this.markerEnd.getPosition());
    map.fitBounds(bounds2);
    alert('showOnMap'); //HERE3*************
}

function codeAddress(address, isStart) {
    geocoder.geocode({ 'address': address }, function (results, status) {
        alert('codeAddress'); //HERE2*************
        if (status == google.maps.GeocoderStatus.OK) {
            if (isStart) {
                markerStart.setPosition(results[0].geometry.location);
            }
            else {
                markerEnd.setPosition(results[0].geometry.location);
            }
        } else {
            alert("Sorry, couldn't find your destination: " + status);
        }
    });
    return;
}
  • 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-03T22:59:46+00:00Added an answer on June 3, 2026 at 10:59 pm

    It’s because geocode is happening asynchronously (non-blocking code, meaning sometime in the future, and I’ll let you know when I’m done). It might be possible to tell Google’s api to work synchronously (as blocking code), but you’d probably be better off putting code that depends on the results in the callback of geocode.

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

Sidebar

Related Questions

just wondering if someone can help me make this code work properly and be
Just wondering if someone can help me out with this quickly. I have a
Just wondering if someone can help me code the following. I want to use
Just wondering if someone can help me with the following issue. I want to
I'm wondering if someone can help me with this. I have three TabPanels depending
Just wondering if someone can help me figure out why my menu is doing
Hey guys, I'm wondering can someone help me out. I'm using javascript to serialize
I was just wondering if someone can help with an annoyance I have with
Just wondering if someone could help me with a very simple SQL query. I
I was wondering if anyone can help me on this cause its driving me

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.