我正在使用以下代码,但没有成功:
//在NativeBase容器内部
<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]}
/>
//在类的 componentDidMount 方法内部
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) },
);
但是出现错误,说没有这样的animateToCoordinate函数。
animateToRegion
需要提供latitudeDelta
和longitudeDelta
参数。另一方面,animateCamera
不需要这些参数,所以在不追踪缩放值的情况下会更容易使用。例如:_mapView.animateCamera({ center: { latitude, longitude }})
。 - nymo