如何在反应本机地图中使用animateToRegion函数?

Dik*_*eep 5 react-native

我正在使用React-native地图群集的MapView和Marker和react-native-maps的标注。我无法使用animateToRegion。它告诉我this.mapView.animateToRegion is not a function

 <MapView
 ref={map=>{mapView = map}}
 provider='google'
 clustering={true}
 onClusterPress={this.onPressCluster}
 region={this.state.region}
 onRegionChange={this.onRegionChange}
 onRegionChangeComplete={this.onRegionChangeComplete}
 style={styles.map}
 showsUserLocation={true}
 followUserLocation={true}
 zoomEnabled={true}
 ScrollEnabled={true}
 showsBuildings={true}
 showsMyLocationButton={false}/>
Run Code Online (Sandbox Code Playgroud)

Mah*_*our 9

animate(){
    let r = {
        latitude: 42.5,
        longitude: 15.2,
        latitudeDelta: 7.5,
        longitudeDelta: 7.5,
    };
    this.mapView.root.animateToRegion(r, 2000);
}

render(){
    return(
        <MapView
            ref = {(ref)=>this.mapView=ref}
            region={{
                latitude: 35.688442,
                longitude: 51.403753,
                latitudeDelta: 0.5,
                longitudeDelta: 0.5,
            }}
            onPress={()=>this.animate()}
        >

           ...markers...

        </MapView>
    );
}
Run Code Online (Sandbox Code Playgroud)

  • 当我尝试这种方法时 `mapView.root` 返回 null,你介意告诉我你使用的是哪个版本的 React Native Maps? (2认同)