如何确保地图加载谷歌地图反应

时间:2018-04-30 19:28:13

标签: reactjs google-map-react

我正在使用google-map-react并需要访问map

我通过执行以下操作来访问引用:

<GoogleMap ref={ref => this.map = ref} />

当我在componentDidMount()上调用引用时this.map.map_,它返回null,因为地图尚未加载。我需要一种方法来在组件安装时访问它。

1 个答案:

答案 0 :(得分:1)

我认为您可以使用onGoogleApiLoaded

handleGoogleApiLoaded = ({map, maps}) => {
  map...
}

<GoogleMap  
  onGoogleApiLoaded={this.handleGoogleApiLoaded}
  yesIWantToUseGoogleMapApiInternals
/>
相关问题