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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T21:37:35+00:00 2026-06-06T21:37:35+00:00

I want to retrieve and store the result of Google Maps API function geocode()

  • 0

I want to retrieve and store the result of Google Maps API function geocode() in order to use it later.
I have put the code below on an OnClick event to reverse geocode the address of the point clicked on the map.

The problem is that it always contains the value of the previous point clicked.
Example: the first time I click it is ‘undefined’, 2nd time it is the address of the point I clicked before and so on.

var address ;


my_listener = google.maps.event.addListener(map, 'click', function(event) {
   codeLatLng(event.latLng);
});

function codeLatLng(mylatLng) {
    
    geocoder = new google.maps.Geocoder();
    var latlng = mylatLng;

    geocoder.geocode({'latLng': latlng}, function(results, status) 
    {
        if (status == google.maps.GeocoderStatus.OK) 
        {
            if (results[1]) 
            {
                address = results[1].formatted_address;
            }
        }
    });

    alert(address);
}
  • 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-06T21:37:37+00:00Added an answer on June 6, 2026 at 9:37 pm

    If you will move alert, inside of callback, you will see the new address:

    geocoder.geocode({'latLng': latlng}, function(results, status) {
        if (status == google.maps.GeocoderStatus.OK) 
        {
            if (results[1]) 
            {
                address = results[1].formatted_address;
                alert(address);   //moved here
            }//   ^
        }//       |
    });//         |  
    //-------------
    

    Geocoding process is asyncronous, so in this case:

    geocoder.geocode({'latLng': latlng}, function(results, status) {
        //We be called after `alert(address);`
    });
    alert(address);
    

    alert will be executed before the geocoding data will be recieved from server and callback function(results, status){} will be called.

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

Sidebar

Related Questions

I store some dates in my NSMutableArray, I want to retrieve them and change
I want to store and retrieve data that is accessible to all activities in
i am using coredata in my application to store and retrieve values.i want to
I want to store values and retrieve them from a Java HashMap. This is
I want retrieve the width and height of browser in pixel(px) using ruby code.
I have a HTML table as follows. I want retrieve row values from this
I've been reading the documentation at: http://code.google.com/intl/nl/apis/maps/documentation/places/#PlaceSearches But How do I modify the Place
I want to retrieve the last row from the data store so how can
I want to store Google search results (both title and link) into database. HTML
So I have a DAO, DTO, and BO. The following code is the result:

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.