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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T22:33:00+00:00 2026-06-11T22:33:00+00:00

I am trying to use the Google Geocoding API to get the latitude and

  • 0

I am trying to use the Google Geocoding API to get the latitude and longitude from the address.I want to store the coordinates inside a variable to use them later on.I know it is a asynchronous call.In the code below I try to use the function useCordinates to assign the coordinates to a global variable so that I can use it later on.But I am getting cordinates is not defined when I debug.I am new to javascript.I read somewhere that implied global variables do not need to be defined.

myGlobalVar = ‘Hello world’;
Thanks for the help.

 function codeAddress(address){
  var loc=[];
  geocoder.geocode( { 'address': address}, function(results, status) {
  if (status == google.maps.GeocoderStatus.OK) {
     // no need to define it in outer function now
    loc[0]=results[0].geometry.location.lat();
    loc[1]=results[0].geometry.location.lng();

    useCordinates( loc ); 

  } else {
    alert("Geocode was not successful for the following reason: " + status);
  }
});
}

function useCordinates(cordinateArray){
 cordinates= cordinateArray;
  }
functionTestCodeAddress(){
 start = document.getElementById('start').value;
 codeAddress(start);
 //assign the global variable 'cordinates'
 document.getElementById('start').value=cordinates; 
}
  • 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-11T22:33:01+00:00Added an answer on June 11, 2026 at 10:33 pm

    The problem is not the variable, the problem is when you try to access the variable.

    Currently you do it inside TestCodeAddress() immediately after the call of codeAddress(), that’s to early because the asynchronous request has not been finished yet at this time.

    You may e.g. move this line:

    document.getElementById('start').value=cordinates; 
    

    into useCordinates()

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

Sidebar

Related Questions

hi i am trying to get latitude and longitude values by address function get_lat_long_from_address($address)
I'm trying to use Google geocoder service to get the coordinates of cities input
Am trying to use google.loader.ClientLocation along with the maps api to get the location
we are trying to use the Google YouTube API to upload videos from our
I've been trying to get a json response from google's geocoding service. I'm using
I am trying to use google maps API V3 to draw a line from
I'm trying to use Google Analytics API to query internal searches that happen on
I'm trying to use Google's Images API to search an image and put it
I'm trying to use the geocoding code from here in my ASP.NET MVC 2
I use the StreamReader class to obtain XML for my GeoCoding process from Google.

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.