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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T07:48:20+00:00 2026-06-11T07:48:20+00:00

I am trying ReverseGeCoding its working but i cant get return value function reverseGeoCode(lat,lng)

  • 0

I am trying ReverseGeCoding its working but i cant get return value

function reverseGeoCode(lat,lng) {
 var reverseGeoAddress = '';
 var geocoder = new google.maps.Geocoder();
 var latlng = new google.maps.LatLng(lat, lng);
 geocoder.geocode({'latLng': latlng}, function(results, status) {
     if (status == google.maps.GeocoderStatus.OK) {
         if (results[1]) {
             if(results[1].formatted_address.length){
                 reverseGeoAddress = results[1].formatted_address;
                 //NOTE: when i console.log(reverseGeoAddress );
                 //its working fine i am getting the address
                 return reverseGeoAddress;
                   //but return not working.

             }  
         }
      } 
  });
}

when i call my function like

   var address = reverseGeoCode(31.518945,74.349316);

now every time my address variable is “undefined”;
why is this doing so??
Any hint ?

  • 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-11T07:48:22+00:00Added an answer on June 11, 2026 at 7:48 am

    Function reverseGeoCode is not having any return value

    return reverseGeoAddress; is inside anonymous function.
    

    Simple fix would be – you can possibly use callback since it is asynchronous function. “callback” can be a handler from the place you invoke.

    // Invoking reverseGeoCode....
    reverseGeoCode(lat,lng, function(myAddress){ 
      // Your custom code goes here...
    });
    
    function reverseGeoCode(lat,lng, callback) {
    var reverseGeoAddress = '';
     var geocoder = new google.maps.Geocoder();
     var latlng = new google.maps.LatLng(lat, lng);
     geocoder.geocode({'latLng': latlng}, function(results, status) {
         if (status == google.maps.GeocoderStatus.OK) {
             if (results[1]) {
                 if(results[1].formatted_address.length){
                     reverseGeoAddress = results[1].formatted_address;
                     // Callback the handler if it exists here
                     // No return value
                     callback(reverseGeoAddress);
                 }  
             }
          } 
      });
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

trying to get a project working on my debian vm but foreman refuses to
Trying to find some information on this but am unable to get any results
Trying to get integer part of float.MaxValue but it is throwing error? long l
Trying to get jquery AutoComplete to return and populate it's dropdown. The input and
trying to get my first HTML/CSS uni assignment sorted but have become a bit
Trying to parse time from string, but get this error. Tried few formatting string.
Trying to get a wildcard search to pick up on any text in org_name
Trying to implement LoaderManager + CursorLoader. In onFinish method adapter should swap its cursor
trying to get same string on tooltip as is in the Text e.g. Text=<%#
Trying to pull a value from the sunrise element from [yweather:astronomy] in the Yahoo

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.