如何使用搜索结果中的新区域更新 Mapview

Afr*_*jie 0 react-native react-native-maps

在用户从 GoogleAutoComplete 搜索位置后,我希望 MapView 根据提供的数据(纬度、经度)显示或加载新区域。

我正在使用这个 airbnb 包https://github.com/react-native-community/react-native-maps

我试过了onRegionChange,我没有找到合适的功能来实现这一点。这是我的地图视图

 <MapView
    provider={PROVIDER_GOOGLE} 
    style={style.map}
    region={{
        latitude: 37.78825,
        longitude: -122.4324,
        latitudeDelta: 0.015,
        longitudeDelta: 0.0121,
     }}
    >
</MapView>
Run Code Online (Sandbox Code Playgroud)

用户单击结果后,地图应移动到或显示该区域。

小智 5

您应该使用初始区域创建一个状态

state = { 
   region: {
    latitude: 37.78825,
    longitude: -122.4324,
    latitudeDelta: 0.015,
    longitudeDelta: 0.0121,
 }
}
Run Code Online (Sandbox Code Playgroud)

接下来,将其赋予 mapView 中的 region 属性,并在搜索后更新区域状态

<MapView
provider={PROVIDER_GOOGLE} 
style={style.map}
region={this.state.region}
>
</MapView>
Run Code Online (Sandbox Code Playgroud)