首页 > 解决方案 > 在 Mapview Marker 标题上反应原生 onPress 事件?

问题描述

使用下面的代码,如果我单击标记,它会导航到我提到的页面,但我希望在标记标题而不是标记上实现这一点,有什么方法可以使标题可点击。请提供任何帮助。

 return (
    <MapView
      style={styles.map}
      placeholder="Search location"
      minLength={2}
      region={focusRegion}
      // onPress={componentDidMount()}
      onMapReady={getLocationHandler}
      showsUserLocation={true}
      //followsUserLocation={true}
      loadingEnabled={true}
      loadingIndicatorColor={"#606060"}
    >
      {places.map((marker) => (
        <Marker
          key={marker.id}
          coordinate={{ latitude: marker.lat, longitude: marker.lng }}
          title={(marker.title)}
          onPress={() => {
            props.navigation.navigate("PlaceDetail", {
              placeTitle: marker.title,
              placeId: marker.id,
            });
          }}
        >              
            
    </MapView>
  );

标签: javascriptreactjsreact-nativegoogle-mapsreact-native-maps

解决方案


它适用于标注

<MapView.Callout
            title={true}
            width={210}
            onPress={() => {
              props.navigation.navigate("PlaceDetail", {
                placeTitle: marker.title,
                placeId: marker.id,
              });
            }}
          ></MapView.Callout>

推荐阅读