我一直在尝试使用 MapView 上的方法为区域设置动画,为此我需要访问 ref 但它未定义。其他一切都正常工作,我只是无法获得参考,并且任何时候我尝试调用一个方法,例如`
this.map.animateToRegion({
latitude: 0,
longitude: 0,
latitudeDelta: 1,
longitudeDelta: 1
});
Run Code Online (Sandbox Code Playgroud)
我收到一条错误消息:
无法读取未定义的属性“animateToRegion”
<MapView
ref={r => this.map = r}
mapPadding={{ top: 0, left: 0, right: 0, bottom: 400 }}
provider='google'
style={{ flex: 1 }}
region={this.region}
>
{this.renderBarberMarkers()}
</MapView>
Run Code Online (Sandbox Code Playgroud)