【问题标题】:Cannot use the function hideCallout from react native maps无法从反应原生地图中使用函数 hideCallout
【发布时间】:2020-04-22 22:28:15
【问题描述】:

当我按下应用上卡片的 X 按钮时,我目前正试图关闭我的标注。

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

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

    this.markers.hideCallout();

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

这是我的** Map View 代码,我使用 RN Clustering **

<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>

最后在同一个文件的这个组件中调用了unset card函数:

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

如果有人告诉我如何使用标记的引用,我将不胜感激,因为尽管我尝试了很多,但它不起作用。

提前致谢,

【问题讨论】:

    标签: reactjs react-native react-native-maps


    【解决方案1】:

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

    初始化标记

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

    创建标记参考

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

    需要时拨打电话

    this.markers[id].hideCallout();
    

    我希望有一天有人会觉得它有帮助

    【讨论】:

    • 感谢分享!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-09-29
    相关资源
    最近更新 更多