Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
React native 如何在react原生贴图中使用animateToRegion函数?_React Native - Fatal编程技术网

React native 如何在react原生贴图中使用animateToRegion函数?

React native 如何在react原生贴图中使用animateToRegion函数?,react-native,React Native,我正在使用react原生地图群集的MapView和react原生地图的标记和标注。我无法使用animateToRegion。 它向我显示this.mapView.animateToRegion不是一个函数 <MapView ref={map=>{mapView = map}} provider='google' clustering={true} onClusterPress={this.onPressCluster} region={this.state.region}

我正在使用react原生地图群集的MapView和react原生地图的标记和标注。我无法使用
animateToRegion
。 它向我显示
this.mapView.animateToRegion不是一个函数

 <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}/>
{mapView=map}
提供商=“谷歌”
集群={true}
onClusterPress={this.onPressCluster}
region={this.state.region}
onRegionChange={this.onRegionChange}
onRegionChangeComplete={this.onRegionChangeComplete}
style={style.map}
showsUserLocation={true}
followUserLocation={true}
zoomEnabled={true}
ScrollEnabled={true}
showsBuildings={true}
showsMyLocationButton={false}/>
动画制作(){
设r={
纬度:42.5,
经度:15.2,
latitudeDelta:7.5,
纵向德尔塔:7.5,
};
这个.mapView.root.animateToRegion(r,2000);
}
render(){
返回(
this.mapView=ref}
区域={{
纬度:35.688442,
经度:51.403753,
纬度德尔塔:0.5,
纵向德尔塔:0.5,
}}
onPress={()=>this.animate()}
>
…标记。。。
);
}
单击搜索地址=(placeId、索引、dscrpt)=>{
getLatLongFromAddress(placeId)。然后((响应)=>{
设r={
[Constants.KEY_LATITUDE]:response.geometry.location.lat,
[常数.键经度]:response.geometry.location.lng,
latitudeDelta:latitudeDelta,
longitudeDelta:longitudeDelta
}
this.mapView.animateToRegion(r,1000)
键盘
IsSetText编程=真;
这是我的国家({
搜索:dscrpt,
searchData:[],
})
}).然后((错误)=>{})
}
this.mapView=ref}
提供者={provider_GOOGLE}
style={[style.map,{width:this.state.width}]}
initialRegion={region}
onRegionChangeComplete={this.onRegionChange}
showsMyLocationButton={true}
showsCompass={true}
showsUserLocation={true}
onMapReady={()=>this.setState({width:width-1})}
/>

我认为问题在于道具不是ref,而是mapRef。在那里传递ref,它应该会工作


然后您还必须使用类似这样的东西调用它
this.mapView。[current/map]animateToRegion
。只需检查您得到的mapView对象。

当我尝试这种方法时,
mapView.root
返回null,您介意告诉我您使用的是哪个版本的React原生地图吗?只需使用
this.mapView.animateToRegion(r,2000)您能告诉我们如何使用功能组件和useRef@yaswanthkoneri . 我也是,在react native map中的useRef也遇到了同样的问题。当我做ref={ref=>mapRef=ref}时,我在mapRef中得到null,如果我做ref={mapRef},在这种情况下,我无法得到“animateToCoordinate”函数。请帮助我,如果你找到了这个问题的任何解决方案,否则我将不得不创建一个类组件。