无法在React Native Maps中使用函数hideCallout

问题描述 投票:0回答:1

我目前正在尝试在我的应用上按卡片上的X按钮时关闭标注。

我的代码是这个。 **关卡功能**

  unsetCard = id => {
    this.setState({
      ...this.state,
      showCard: false,
    });

    this.markers.hideCallout();

    if (this.state.keyboard) {
      Keyboard.dismiss();
    }
  };

这是我的**地图视图代码,我使用RN群集**

<MapView
            // 
            mapRef={ref => (this.myMapRef = ref)}
            //
            onPress={this.unsetCard}>
            {this.props.data.map(marker => (
              <Marker
                key={marker.id}
                ref={ref => (this.markers = ref)}
               //
               }>
                <Callout
                  //
                  }}>
                  <CustomCallout title={marker.t} />
                </Callout>
              </Marker>
            ))}
          </MapView>

最后,在同一文件中的该组件中调用未设置卡的功能:

            <CustomCardWithImage
              close={() => this.unsetCard(this.state.cardInfo.id)}
            />

如果有人告诉我如何使用标记的ref,我将不胜感激,因为我尝试过的所有方法都无法使用。

谢谢,

reactjs react-native react-native-maps
1个回答
0
投票

[认真考虑不继续使用此应用程序后,我休息了一会,解决了问题。如果您有兴趣,可以使用以下方法显示或隐藏标注:

初始化标记

  constructor(props) {
    super();
    this.markers = [];
  }

创建标记参考

<Marker
  key={marker.id}
  ref={ref => {
  this.markers[marker.id] = ref;
}}>

在需要的地方打电话

this.markers[id].hideCallout();

我希望有一天能对您有所帮助

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.