[英]react-native-maps markers in loop are not rendered
I'm trying to learn how to create React native apps for iOS. 我正在尝试学习如何为iOS创建React本机应用程序。 I use
react-native-maps
package and when I render MapView.Marker
statically, it renders to the map properly. 我使用
react-native-maps
包,当我静态渲染MapView.Marker
,它会正确渲染到地图。 But when I want to render array of markers, nothing happens. 但是,当我要渲染标记数组时,什么也没发生。
export default (props) => {
return (
<MapView
initialRegion={{
latitude: 48.99568000,
longitude: 21.24220000,
latitudeDelta: 0.001,
longitudeDelta: 0.01
}}>
{/* this works */}
<MapView.Marker
coordinate={{
latitude: 48.98975,
longitude: 21.24697
}}
/>
{/* this doesn't */}
{
props.points.nearby.map(point => {
<MapView.Marker
coordinate={{
latitude: point.lat,
longitude: point.lng
}}
/>
})
}
</MapView>
);
}
props.points.nearby
array is OK, there are three items props.points.nearby
数组还可以,有三项
Solution: 解:
As I realized, ES6 arrow functions with block bodies do not implicity return , so I added return
statement to my map
callbacks and now everything works well. 正如我意识到的那样, 带有块体的ES6箭头函数不会隐式return ,所以我在
map
回调中添加了return
语句,现在一切正常。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.