Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

86
Views
How to update my global variables with information from a Google Geocoder async function

I am using the Google Geocoder API to get coordinates given an address, and I currently have this function:

var latitude = 0;
var longitude = 0;

  const test = getGeocode(
    location[0].address,
    process.env.NEXT_PUBLIC_API_KEY,
  ).then(
    (response) => {
      latitude = response.data.results[0].geometry.location.lat;
      longitude = longitude = response.data.results[0].geometry.location.lng;
    },
    (error) => {
      console.error(error);
    },
  );

When I console.log the lat and long values inside of the const test, the values print correctly. However, I am unable to save these values into the longitude and latitude global variables as I need to. Is there anything I can do to save the long and lat values from my const test into global variables so that I can use them elsewhere? (My ultimate goal is to display the location of the long/lat on a map on my site.)

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!