小编Cra*_*ues的帖子

无法获得对 MapView 的引用 - react-native-maps

我一直在尝试使用 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)

reactjs react-native react-native-maps

5
推荐指数
3
解决办法
4788
查看次数

标签 统计

react-native ×1

react-native-maps ×1

reactjs ×1