1

I am having trouble with the onPress handler in a marker component. onPress never seems to get called because it never calls onMarkerPress which prints out something to the console. Does anyone have this issue?

Here is my code:

const AnimatedTouchable = Animated.createAnimatedComponent(TouchableOpacity);

{filteredMarkers.map((marker, index) => {
             const scaleStyle={
               transform: [
                 {
                   scale: interpolations[index].scale,
                 }
               ]
             }
             return (
               <View style={styles.container}>
                <MapView
                ref={_map}
                initialRegion={state.region}
                provider={PROVIDER_GOOGLE}>
                  <Marker key={index} coordinate={marker.coordinate}>
                    <AnimatedTouchable style={[styles.markerWrap]} onPress={(e) => console.log(onMarkerPress(e))}>
                      <Animated.Image
                        source={require('../assets/map-marker.png')}
                        style={[styles.marker, scaleStyle]}
                        resizeMode="cover"
                      />
                    </AnimatedTouchable>
                  </Marker>
                  
                </MapView>
              </View>
             );
           })}

onMarkerPress:

const onMarkerPress = (mapEventData : any) => {
      {console.log("PRESSED")}
      const markerID = mapEventData._targetInst.return.key;

      let x = (markerID * CARD_WIDTH) + (markerID * 20); 
      x = x - SPACING_FOR_CARD_INSET;
      

      _scrollView.current.scrollTo({x: x, y: 0, animated: true});
    }
Shoaib Khan
  • 1,020
  • 1
  • 5
  • 18
Tyra
  • 11
  • 1
  • hi, perhaps a callout is needed https://stackoverflow.com/questions/39654594/marker-click-event-on-react-native-maps-not-working-in-react-ios – jspcal Feb 16 '22 at 01:07
  • I did see that post but when I add touchableHighlight and a callout my markers disappear. Although what should my callout styling look like? – Tyra Feb 16 '22 at 01:14

0 Answers0