无法更新 MapView 的 onRegionChange() 方法中的状态变量



尝试更新 MapViewonRegionChange(( 方法中的region参数时,我遇到了this.setState is not a function

<MapView
  ref = {(ref) => {this.mapRef = ref}}
  provider={PROVIDER_GOOGLE} 
  onRegionChange={this.onRegionChange}
  region={this.state.region}>
</MapView> 
 onRegionChange(region_) {
  //console.log(region_);
  this.setState({region:region_}); 
}
// Initial region value in *constructor*
constructor(props){
super(props); 
this.state = { 
        region: {
         latitude: 0,
         longitude: 0,
         latitudeDelta: 0,
         longitudeDelta: 0 
      }
    }
}

我也尝试用更新变量。

this.state.region.setValue(region_);

constructor方法中添加:

constructor(props) {
    super(props);
    this.onRegionChange = this.onRegionChange.bind(this); //add this
}

最新更新