如何访问 react-native-maps MapView 的所有 MapView.Markers?

How to access all the MapView.Markers of a react-native-maps MapView?

在使用 react-native-maps 的 react-native 应用程序中,我试图以编程方式显示许多特定 MapView.MarkerMapView.Callout。我打算使用 showCallout 方法,但还没有找到如何访问所有 MapView 标记的方法,从那里我可以 select 基于它 id/key/ref 的正确标记。

标记在地图循环中呈现到 MapView 上,如下所示。

到目前为止,我已经尝试使用 this.refs.mapView.refs / this.refs.mapView.children 来获取所有 MapView 的标记,但没有成功,但我没有得到任何东西。

<MapView>
    ref={'mapView'}
    ...
>
    {this.props.screenProps.appState.cachedDeviations.map(deviation => {
        return (
            <MapView.Marker
                coordinate={
                    deviation.position
                }
                key={deviation.Id}
                ref={deviation.Id}
            >
                <MapView.Callout style={styles.callout}>
                    <DeviationCallout
                        ...
                    />
                </MapView.Callout>
            </MapView.Marker>
        )
    })
}
</MapView>

有什么提示吗?

您可以使用函数式引用

例子

<MapView.Marker
    coordinate={ deviation.position }
    key={deviation.Id}
    ref={(ref) => this.markers[deviation.Id] = ref}
>
  // ...
</<MapView.Marker>

// ...

this.markers[someId].showCallout();