我开始了我的项目create-react-app
,并安装了google-maps-react
.
现在我想为每个Marker 分配 InfoWindow,这样我就可以一次显示很多。(也许答案很明显,但对我来说不是......)
我的代码:
export class MapContainer extends Component {
render() {
return (
<Map
className={'map'}
google={this.props.google}
zoom={13}
initialCenter={{lat: 54.753986, lng: 24.670219}}
style={nullStyle}
>
{this.props.places.map(place => (
<Marker
key={`marker-${place.name}`}
title={place.title}
name={place.name}
position={place.position}
/>
))}
{this.props.places.map(place => (
<InfoWindow
key={`infowindow-${place.name}`}
marker={_JUST_BEFORE_CREATED_MARKER_}
visible={true}>
<div>{place.title}</div>
</InfoWindow>
))}
</Map>
)
}
}