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

106
Views
la función axios se ejecuta después de otras líneas de código

Mi código:

 var latlng = {lat: 7, lng: 7}; function findLatLng() { var testLocation = '350 Victoria St, Toronto'; axios.get('https://maps.googleapis.com/maps/api/geocode/json', { params: { address: testLocation, key: 'MY KEY', } }) .then(function(response) { console.log(response.data.results[0].geometry.location); return response.data.results[0].geometry.location; }) .catch(function(error) { console.log(error); }); } latlng = findLatLng(); console.log(latlng);

En la consola, latlng se registra como indefinido, pero console.log(response.data.results[0].geometry.location) se registra con el valor adecuado;
también se registra después aunque debería haberse ejecutado primero.

Creo que esto se debe a que el código continúa a pesar findLatLng() no se realiza con la solicitud, pero no estoy seguro. Cuando compruebo el valor de latlng en la consola después, se convierte en el valor correcto.

¿Cuál es el problema y cómo soluciono esto, por favor?

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!