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

103
Views
Return value from Geocode Promise

I'm using the react-geocode api to get coordinates from a string address (like 1234 home street, etc.). So far, this is my code.

async function ConvertAddress(address) {
      if (address !== "") {
        Geocode.fromAddress(address, resolve).then(
            (response) => {
              const { lat, lng } = response.results[0].geometry.location;
              const center = { lat: lat, lng: lng}; // if I console logged center from here, it would work fine.
              return center;


            },
            (error) => {
              alert("ConvertAddress error:", error);
            }
            
        );
      }
    }

However, I'm not sure how to access "center" from outside this function (such as from another function). I've tried this:

console.log("ConvertAddress test", ConvertAddress(data[0]));

And it returns this:

ConvertAddress test 
Promise { <state>: "fulfilled", <value>: undefined }
​
<state>: "fulfilled"
​
<value>: undefined
​
<prototype>: Promise.prototype { … }

Can I have some help with returning center in such a way that I can call it without it being undefined? Thanks in advance.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Try this

async function ConvertAddress(address) {
      if (address !== "") {
       var addressResult = await Geocode.fromAddress(address, resolve).then(
            (response) => {
              const { lat, lng } = response.results[0].geometry.location;
              const center = { lat: lat, lng: lng}; // if I console logged center from here, it would work fine.
              return center;
            },
            (error) => {
              return "error in results"
            }
        );
        addressResult.then(function(result){ 
            console.log(result);
        }) 
      }
    }
about 4 years ago · Juan Pablo Isaza Report
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!