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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T04:35:37+00:00 2026-05-21T04:35:37+00:00

I have a (hopefully quite simple) Javascript problem. I’ve search but found nothing that

  • 0

I have a (hopefully quite simple) Javascript problem. I’ve search but found nothing that is really relevant to the problem.

Basically I have a function (addToGlobe) that calls two other functions (codeAddressLat and codeAddressLng) as it runs. The two called functions should both return a float value to the first function, which then uses them. The subfunctions definitely work correctly – I did a print statement to check that the “numfinal” variable in each has a value, and it does.

However, when I add print statements to the calling function (as commented in the code), it returns ‘undefined’. Therefore, the problem seems to be when the numfinal value is returned.

Thanks 🙂

function addToGlobe(uname, uid, pmcity) {
    // Get lat & long of city
    var pmlat = codeAddressLat(pmcity);
    var pmlong = codeAddressLng(pmcity);

    log(pmlat);   // PROBLEM! Prints 'undefined'
    log(pmlong);  // PROBLEM! Prints 'undefined'

    // Rest of function removed to keep it simple
}

function codeAddressLat(inputcity) {
    geocoder = new google.maps.Geocoder();
    var latlng = new google.maps.LatLng(-34.397, 150.644);

    geocoder.geocode( { 'address': inputcity}, function(results, status) {
      if (status == google.maps.GeocoderStatus.OK) {
          var llsplit = new Array();

          bkresult = String(results[0].geometry.location);
          bkresult = bkresult.replace(/[\(\)]/g, "");
          llsplit = bkresult.split(',');

          numfinal = parseFloat(llsplit[0]);
          return numfinal;

      } else {
        log('<b><font color="#C40031">Geocode was not successful:</b> ' + status);
      }
    });
 }

  function codeAddressLng(inputcity) {
        // Basically the same function as above. Removed for simplicity
     }
  • 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-21T04:35:38+00:00Added an answer on May 21, 2026 at 4:35 am

    codeAddressLat is not actually returning anything. The anonymous function it passes to geocoder.geocode is.

    Since geocoder.geocode is running asynchronously, codeAddressLat can’t wait around for its answer. So codeAddressLat really can’t return anything of value. Instead codeAddressLat needs to become asynchronous too. This is a common pattern in JavaScript.

    function addToGlobe(uname, uid, pmcity) {
         codeAddressLat(pmcity, function(pmlat) {
            // do something with pmlat
        });
    
        ...
    }
    
    function codeAddressLat(inputcity, callback) {
        geocoder = new google.maps.Geocoder();
        var latlng = new google.maps.LatLng(-34.397, 150.644);
    
        geocoder.geocode( { 'address': inputcity}, function(results, status) {
          if (status == google.maps.GeocoderStatus.OK) {
              var llsplit = new Array();
    
              bkresult = String(results[0].geometry.location);
              bkresult = bkresult.replace(/[\(\)]/g, "");
              llsplit = bkresult.split(',');
    
              numfinal = parseFloat(llsplit[0]);
    
              // instead of returning, call the callback with the result
              callback(numfinal);
    
          } else {
            log('<b><font color="#C40031">Geocode was not successful:</b> ' + status);
          }
        });
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is a (hopefully) really simple question - I have been told recently that
What I'm trying to do is (hopefully) simple, but I just don't quite have
I have a weird date rounding problem that hopefully someone can solve. My client
Ok, simple problem hopefully. I have started to make a simple server for a
Hopefully this is a really quick one ;) I have written a lexer /
I have a very simple demo working that uses Webkit transforms and transitions for
Hi this question or problem i have its very hard i have search and
I have the following code (Yes I know it's quite long winded, but I
I have been working on a WCF service library where hopefully all the business
This will hopefully be an easy one. I have an F# project (latest F#

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.