【问题标题】:React native onPress event on Mapview Marker title?在 Mapview Marker 标题上反应原生 onPress 事件?
【发布时间】:2020-07-24 13:20:21
【问题描述】:

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

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

【问题讨论】:

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


    【解决方案1】:

    它适用于标注

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-04-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多