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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T07:59:29+00:00 2026-05-28T07:59:29+00:00

I am having issues passing two coordinates from one function to another. I don’t

  • 0

I am having issues passing two coordinates from one function to another. I don’t really know JavaScript, but it seems to be somewhat correct. Could you please let me know where is my error?

        <script type="text/javascript"> 

        function initialize() {
            var address = "Chicago IL";
            locs= getLatLong(address);

            alert(locs.lat()); //does not work
            var myOptions = {
                zoom: 4,
                center: new google.maps.LatLng(41, -87),
                mapTypeId: google.maps.MapTypeId.ROADMAP          
            };

            var map = new google.maps.Map(document.getElementById('map_canvas'),
            myOptions); 
        }

        function getLatLong(address){
            var geo = new google.maps.Geocoder;
            geo.geocode({'address':address},function(results, status){
                if (status == google.maps.GeocoderStatus.OK) {

                    locations[0] = results[0].geometry.location.lat(); 
                    locations[1] = results[0].geometry.location.lng();                  

                    //alert(locations[0]); //test is good- works! Need to pass it back to function
                    //alert(locations[1]); //test is good- works! Need to pass it back to function
                    locs =results[0].geometry.location; 
                    return locs;                
                } else {
                    alert("Geocode was not successful for the following reason: " + status);
                }
            });
        }
    </script>
  • 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-28T07:59:30+00:00Added an answer on May 28, 2026 at 7:59 am

    It is not possible to return a value from an asynchronous function. Do not try it.

    Use a callback instead.

    function setLocationOnMap(locs) {
        alert(locs.lat()); // works now!
        var myOptions = {
            zoom: 4,
            center: new google.maps.LatLng(41, -87),
            mapTypeId: google.maps.MapTypeId.ROADMAP          
        };
        var map = new google.maps.Map(document.getElementById('map_canvas'), myOptions); 
    }
    
    function initialize() {
        var address = "Chicago IL";
        getLatLong(address, setLocationOnMap);
    }
    
    function getLatLong(address, callback){
        var geo = new google.maps.Geocoder;
        geo.geocode({'address':address},function(results, status){
            if (status == google.maps.GeocoderStatus.OK) {
                // processing...
                locs = results[0].geometry.location; 
    
                callback(locs);
            } else {
                alert("Geocode was not successful for the following reason: " + status);
            }
        });
    }
    

    You must understand that asynchronous function calls like geo.geocode() return immediately, i.e. before any result is ready. That’s why you can’t use return to return a value from them – they don’t have it yet.

    Once the result (most often, an HTTP request) is ready, the asynchronous function relies on a callback function to handle it. You must do all your further processing in that callback function, either directly or by making another function call.

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

Sidebar

Related Questions

Having issues referencing $(this) from within a the nested ajax 'success' function... I know
I'm having issues passing an array struct into a function for processing. I think
I'm having issues passing arguments through run to the windows side To demonstrate, it
I am having issues converting a png to tiff. The conversion goes fine, but
I am having issues counting the array elements after passing it into an arguement
This question is pretty generic actually, but I'm really having trouble finding a good
I'm having some issues passing vectors to functions. My concern is not with my
I'm having issues passing in an appropriate Java data type for the fetchByType C
I'm having issues passing my list object to my controller - using an ajax
I'm having issues passing on multiple $_GET variables with next. I'm redirecting users to

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.