标记不显示在 React Native 的地图上

Markers not Show on maps in React Native

您好,我得到了一个位置数组,我想在地图中添加标记

我用这段代码,相机没问题,当我使用数组标记添加的第一个对象时,但是当我想添加所有标记时都没有添加!!

这是可能的代码:

<View >
  <MapView
    provider={PROVIDER_GOOGLE}
    onLayout={this.onMapLayout}
    style={styles.map}
    initialRegion={{
      latitude: this.props.data ? this.props.data[0].YPOINT : '',
      longitude: this.props.data ? this.props.data[0].XPOINT : '',
      latitudeDelta: 0.0922,
      longitudeDelta: 0.0421,
    }}

  >

    {this.state.isMapReady && this.props.data.map((value, index) => {

       { console.log("index is : " +index+"\n Ypoint : " + value.YPOINT+ " Xpoint : " + value.XPOINT)}
      <Marker
        key={index}
        coordinate={{
          latitude: value.YPOINT,
          longitude: value.XPOINT,
        }}
      />
    })}

  </MapView>
</View>

我的代码有误?

感谢帮助。

你需要 return 从 map 喜欢,

{this.state.isMapReady && this.props.data.map((value, index) => {
      console.log("index is : " +index+"\n Ypoint : " + value.YPOINT+ " Xpoint : " + value.XPOINT)
      //return your marker here
      return <Marker
        key={index}
        coordinate={{
          latitude: value.YPOINT,
          longitude: value.XPOINT,
        }}
      />
    })
}