1

I an using "import MapboxGL,{MarkerView} from "@react-native-mapbox-gl/maps" for maps.

      return (      
  <MarkerView coordinate={coordinate}  key={key}  onPress= {()=>console.log("pressed")}>   
      <View style={{
          height: 20, 
          width: 70, 
          backgroundColor: '#fff', 
         
          borderColor: '#fff', 
          borderWidth: 3
        }} 
      >
                                              
                <TouchableHighlight onPress= {()=>console.log("pressed")}>

                  <Text style={{color:"#000000"}} >{label}</Text>
                  </TouchableHighlight>

        </View>
       
  </MarkerView>

 );
 };

On press event is not working with marker view here.

Rupak
  • 409
  • 1
  • 3
  • 18

1 Answers1

2

Actucally onPress property is not exist on MarkerView check here

https://github.com/react-native-mapbox-gl/maps/blob/master/docs/MarkerView.md

Instead of MarkerView use MapboxGL.PointAnnotation and in this you can use it's onSelected function like that:

<MapboxGL.MapView
     ref={(c) => (this._map = c)}>
         <MapboxGL.PointAnnotation
              onSelected={() => console.log("pressed")}
         >
            <Image source={require('./assets/marker.png')} />
         </MapboxGL.PointAnnotation>
</MapboxGL.MapView>

for more properties requirement check:

https://github.com/react-native-mapbox-gl/maps/blob/master/docs/PointAnnotation.md

Vishal Pawar
  • 1,447
  • 8
  • 10