嗨,我是React Native的新手,想问一下如何在地图中渲染多个标记。
这是我的代码:
类内部:
constructor(props) {
super(props);
this.state = {
coordinate: ([{
latitude: 3.148561,
longitude: 101.652778,
title: 'hello'
},
{
latitude: 3.149771,
longitude: 101.655449,
title: 'hello'
}
]),
};
}
在render内部:
<MapView
style={styles.map}
showsUserLocation={true}
followUserLocation={true}
zoomEnabled={true}
//annotations={markers}
>
<MapView.Marker
coordinate={this.state.coordinate}
title={this.state.coordinate.title}
/>
</MapView>
我想在地图上显示这两个标记,但我还不知道如何在React Native中制作循环以将它们渲染出来。我已经尝试文档中的内容,但仍然无法工作。
预先感谢您:)
{this.state.markers.map((marker, index) => ( <MapView.Marker key={index} coordinate={marker.coordinates} title={marker.title} /> ))}
- Ryan Walker