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

3
我目前正在尝试在我的应用程序中,当我按下卡片上的X按钮时关闭我的callout。
我的代码如下。**关闭卡片的函数**
  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来引用标记,因为尽管我尝试了很多次,但它并没有起作用。

提前致谢,

1个回答

8

在认真考虑不继续使用此应用程序后,我休息一下并解决了这个问题。如果您感兴趣,以下是如何使用显示或隐藏 callout:

初始化标记

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

创建标记引用

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

适时调用

this.markers[id].hideCallout();

我希望有人在某一天会发现这对他们有所帮助


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接