Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

87
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda