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

91
Visualizações
How to get geocoder result from async callback funtion

First of all, I should say that I dont have a lot of experience working with TS/JS.

I am working on an angular project that requires me to find lat, long from a given address and use that value in a different component. I'm using the google geocoder service and my aim is to get lat, long from the results and store it in a global variable.

This is my service call:

var res = this.geocoder.geocode({address: this.address }, getGeoResults);

And this is the callback:

GeoLoc: any;

getGeoResults( results, status) {
    if(status == google.maps.Geocoderstatus.OK) {
     this.geoLoc = results
    }
}

But the issue is that neither can I get the results from the service into 'res' variable as it returns a ZoneAwarePromise nor can I use any other global variable(GeoLoc) to store the results inside the callback function(error: Cannot set property of undefined) as it is an async function.

Please suggest any method either by getting results in res variable or by storing it in another global variable in the callback function. Or any other method where we can get data from a async callback.

Thank you!

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