Quantcast
Channel: Active questions tagged react-native+typescript - Stack Overflow
Viewing all articles
Browse latest Browse all 6214

Placing a marker by clicking anywhere on the mapview screen in react native

$
0
0

My problem is, im trying to make my mapView so everytime I tap on it a marker is created and the marker's latitude and longitude are sent to the console in order to send them using fetch, I found something similar here but it's made in a class and im trying to make it out of fucntion element.

Heres the code:

  constructor(props) {  super(props)  this.state = {    region: {      latitude: 24.92009056750823,       longitude: 67.1012272143364,      latitudeDelta: 0.1,      longitudeDelta: 0.1    },    markers: []  }}<MapView style={styles.map} region={this.state.region}onPress={(e) => this.setState({ markers: [...this.state.markers, { latlng: e.nativeEvent.coordinate }] })}>{    this.state.markers.map((marker, i) => (<MapView.Marker key={i} coordinate={marker.latlng} />    ))}</MapView>  

Viewing all articles
Browse latest Browse all 6214

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>