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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T12:32:38+00:00 2026-06-13T12:32:38+00:00

Okay, so I have searched a while for a solution to this problem, but

  • 0

Okay, so I have searched a while for a solution to this problem, but I have found nothing specifically on this.
And before you point me to Google’s Terms of Service, please read to the ende of the question!

So here’s the idea:
I want to save the Latitude and Longitude of an address into an array using Google’s Geocoder. I managed to calculate all the values correctly, but I just can’t seem to save it to the array. I have already used an anonymous function to pass the address to the function, but the saving is still not working. Please help!

Regarding Google’s Terms of Service: I know that I may not save this code anywhere and not display it in a Google Map. But I need to save it as a kml-file to feed into a Google Map later. I know, it would be much more convenient to just create the Map, but for other reasons that’s not possible.

adressdaten[] is a two-dimensional array with the data of the addresses
This is the code:

for (i=1; i<adressdaten.length-1; i++)  {
//Save array-data in String to pass to the Geocoder
var adresse = adressdaten[i][3] + " " + adressdaten[i][4];
var coordinates;
var geocoder = new google.maps.Geocoder();
    geocoder.geocode( { 'address': adresse}, (function (coordinates, adresse) {
        return function(results, status) {
            if (status == google.maps.GeocoderStatus.OK) {
               var latLong = results[0].geometry.location;
               coordinates = latLong.lat() + "," + latLong.lng();


        } else {
                alert('Geocode was not successful for the following reason: ' + status);
            }
        }
    })(coordinates, adresse));
    adressdaten[i][6] = coordinates;
}
  • 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-13T12:32:39+00:00Added an answer on June 13, 2026 at 12:32 pm

    This is a FAQ. Geocoding is asynchronous. You need to save the results in the callback function which runs when they are returned from the server.

    Something like (not tested)

    Updated to use function closure

    function geocodeAddress(address, i) {
      geocoder.geocode( { 'address': address}, function(results, status) {
        if (status == google.maps.GeocoderStatus.OK) {
           var latLong = results[0].geometry.location;
           coordinates = latLong.lat() + "," + latLong.lng();
           adressdaten[i][6] = coordinates;
        } else {
           alert('Geocode of '+address+' was not successful for the following reason: ' + status);
        }
      });
    }
    
    var geocoder = new google.maps.Geocoder();
    for (i=1; i<adressdaten.length-1; i++)  {
      //Save array-data in String to pass to the Geocoder
      var adresse = adressdaten[i][3] + " " + adressdaten[i][4];
      var coordinates;
      geocodeAddress(addresse, i); 
    

    }

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

Sidebar

Related Questions

I have searched the forum for this , but found no similar question, okay
Okay, so I have searched this site and found many tutorials on how to
Okay, this should be really simple, but I have searched all over for the
Okay, so first, I have searched for this everywhere but it seems like every
I ran some searches but found no available answer to this issue. Okay, my
I've searched SO and this question seems to have been asked multiple times, but
Okay, Ive searched around and found how this is supposed to be done. For
Okay, I have literally searched all over the web, but I didn't find what
Okay i have this problem with every page i make. im not sure what
I have searched everywhere and have yet to get a solution. Okay heres the

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.