简体   繁体   中英

react-native-maps markers in loop are not rendered

I'm trying to learn how to create React native apps for iOS. I use react-native-maps package and when I render MapView.Marker statically, it renders to the map properly. 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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM