I am using the following code with no success:
//Inside of NativeBase Container
<MapView.Animated
ref="map"
style = {styles.map}
showsUserLocation = {true}
zoomEnabled = {true}
showsMyLocationButton = {true}
showsCompass = {true}
showScale = {true}
showsIndoors = {true}
mapType = {this.state.mapTypes[this.state.mapTypeCode]}
/>
//Inside of componentDidMount of the class
navigator.geolocation.getCurrentPosition(
(position) => {
var initialPosition = JSON.stringify(position.coords);
this.setState({position: initialPosition});
let tempCoords = {
latitude: Number(position.coords.latitude),
longitude: Number(position.coords.longitude)
}
this.refs.map.animateToCoordinate(tempCoords, 1);
}, function (error) { alert(error) },
);
But an error occurs saying there is no such function animateToCoordinate.
Unfortunately now animateToCoordinate is deprecated and if you want to do the same, you should use animateCamera or animateToRegion instead.
render() {
return (
<MapView style = {styles.maps}
ref = {(mapView) => { _mapView = mapView; }}
initialRegion = {{
latitude: 6.8523,
longitude: 79.8895,
latitudeDelta: 0.0922,
longitudeDelta: 0.0421,
}}
/>
<TouchableOpacity
onPress = {() => _mapView.animateToRegion({
latitude: LATITUDE,
longitude: LONGITUDE
}, 1000)}>
<Text>Tap</Text>
</TouchableOpacity>
)
}
In my case I used animateToCoordinate() like follows and it works for me:
var _mapView: MapView;
render() {
return (
<MapView style = {styles.maps}
ref = {(mapView) => { _mapView = mapView; }}
initialRegion = {{
latitude: 6.8523,
longitude: 79.8895,
latitudeDelta: 0.0922,
longitudeDelta: 0.0421,
}}
/>
<TouchableOpacity
onPress = {() => _mapView.animateToCoordinate({
latitude: LATITUDE,
longitude: LONGITUDE
}, 1000)}>
<Text>Tap</Text>
</TouchableOpacity>
)
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With