Jozef Cipa
Jozef Cipa

Reputation: 2227

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

Upvotes: 0

Views: 1013

Answers (1)

Jozef Cipa
Jozef Cipa

Reputation: 2227

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.

Upvotes: 4

Related Questions