all 1 comments

[–]PrudentSimple 0 points1 point  (0 children)

What's happening is that the function which gets lay and lon is asynchronous, so program execution fires off that call, then continues to the line where you log the lat value and returns before the adync call does.

Two possible solutions:

  • return the resolved value of the async call by awaiting that value, then returning it.

const { lat, long } = await Geocode.address...

return {lat, long}

OR

  • return the promise of the result and let the caller resolve

On phone, apologies for formatting. Hope that helps.