0

I am making now a google map with react, and I have a problem with display result from placeId. I have this code:

<Marker
    {...marker}
    key={i}
    position={marker.location}
    title={marker.title}
    icon={'icons/' + marker.type + '.png'}
    onClick={() => {
      props.toggleLocationsActive(i);
    }}
    //animation={DROP}
    >
    {i === props.activeKey && (
       geocodeByPlaceId(marker.place_id)
          .then(results => {
             const address = results[0].formatted_address;
             console.log(address);
          })
          .catch(error => console.error(error)),
       <InfoWindow onCloseClick={props.onToggleOpen}>
            <div>{ marker.title }</div>
       </InfoWindow>)}
   </Marker>

And I want to display address taken from this placeId in InfoWindow - with displayed {marker.title}. And I don't know how to do this... Here is a link to this project on GitHub repository: https://github.com/hajczek/Neighborhood---Warsaw-Cultural-Map Maybe some of you know, how can fix this problem ... Thanks for any answer :)

1 Answers1

0

I fixed this problem by this way:

document.getElementById('address').textContent = address;

I put this code to part of 'then':

.then(results => {
     const address = results[0].formatted_address;
     console.log(address);
     document.getElementById('address').textContent = address;
})