[英]Render multiple marker in react-native-maps
Hye,我是 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'
}
]),
};
}
内部渲染:-
<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 中创建循环来渲染它。 我已经尝试过文档中的内容,但仍然无法正常工作。
提前谢谢你:)
coordinate
属性构造不正确。 做这样的事情 -
this.state = {
markers: [{
title: 'hello',
coordinates: {
latitude: 3.148561,
longitude: 101.652778
},
},
{
title: 'hello',
coordinates: {
latitude: 3.149771,
longitude: 101.655449
},
}]
}
内部渲染
<MapView
....
>
{this.state.markers.map(marker => (
<MapView.Marker
coordinate={marker.coordinates}
title={marker.title}
/>
))}
</MapView>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.