Reputation: 21
<MapView style={styles.map}
showsUserLocation = {true}
>
Upvotes: 2
Views: 12413
Reputation: 415
You could make use of ref
here like so:
<MapView ref={map => {this.map = map}} />
and then in the function that you call when you want to center the map, assuming you have the location of the user stored in the state somewhere, you could do this
handleCenter = () => {
const { latitude, longitude, latitudeDelta, longitudeDelta } = this.state.location;
this.map.animateToRegion({
latitude,
longitude,
latitudeDelta,
longitudeDelta
})
}
react-native-maps
uses animateToRegion
to update the shown region of the map to a specific one and you need to supply the method with a region to go to.
You could also update the region
prop on the map programatically to achieve the same effect, without the animation though.
As for the second part of the question, I am not sure I understand what you want to do. Could you maybe reword the second question?
Upvotes: 11