如何在加载时自动打开React Native Maps标记的标注

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

我希望在安装屏幕组件时打开所有标记的所有标注。当前,它仅在单击标记时才打开。

      <View style={styles.container}>
            <MapView 
                style={{ flex: 1 }} 
                region={region}
                onRegionChangeComplete={onRegionChangeComplete}
            >
                {data.posts.map(marker => (
                    <Marker
                        key={marker.id}
                        coordinate={{latitude: marker.latitude, longitude: marker.longitude }}
                        title={marker.title}
                        description={JSON.stringify(marker.price)}
                    >
                        <Callout>
                            <Text>Hello</Text>
                        </Callout>
                    </Marker>
                ))}
            </MapView>
        </View>
reactjs react-native react-native-maps
1个回答
0
投票

使用参考,

 <Marker
       key={marker.id}
       coordinate={{latitude: marker.latitude, longitude: marker.longitude }}
       title={marker.title}
       description={JSON.stringify(marker.price)}
       ref={ref => {
              this.markerRef = ref;
        }}
      >
            <Callout>
                <Text>Hello</Text>
              </Callout>
      </Marker>

然后致电

this.markerRef.showCallout();

您可以查看完整的示例here

showCallout文档

© www.soinside.com 2019 - 2025. All rights reserved.