Is it possible to make a Google Places callback
from getDetails
function asynchronus or return it's value?
Essentially, in my react app, I am trying to do the following:
- pass a
placeId
to google places api - wait for google to bring back some place information (address, photos, etc)
- make a call to my local api to do something with this data from google
What happens though is
- google goes to get the data
- the call to my api is made but google has not brought back the data yet
I have tried using useState
however, the state is not updated right away and thus I am not sure how to "wait" for google places to finish getting data before continuing my call
example of what I am trying to do (obviously wrong)
const [value, setValue] = useState('')
const foo = async (placeId) => {
var service = new window.google.maps.places.PlacesService(
predictionsRef.current,
)
await service.getDetails(
{
placeId,
fields: ['photos'],
},
async place =>
await setValue(
place.photos[0].getUrl({ maxWidth: 1280, maxHeight: 720 }),
),
)
// I want 'value' to have google place data before the axios call
await axios.post(...)
}
I have looked at the following links so far but can't piece together what I need: