reactjs - 如何确保地图已加载 google-map-react
问题描述
我正在使用google-map-react
并且需要访问map
.
我通过执行以下操作访问 ref:
<GoogleMap ref={ref => this.map = ref} />
当我componentDidMount()
像这样调用 ref 时,this.map.map_
它返回 null 因为地图尚未加载。我需要一种在组件安装时访问它的方法。
解决方案
我认为您可以使用onGoogleApiLoaded:
handleGoogleApiLoaded = ({map, maps}) => {
map...
}
<GoogleMap
onGoogleApiLoaded={this.handleGoogleApiLoaded}
yesIWantToUseGoogleMapApiInternals
/>
推荐阅读
- r - 数据表中最常见的
- javascript - 从特定数据重新排序数组
- javascript - 等待 DOM 元素然后做出反应 - Reactjs
- debugging - 正确使用 DEBUG_NEW
- python - 如何在 Tkinter 中格式化来自 Text Widget 的文本输入
- ansible - 如何为 ansible 变量提供选项卡空间
- http - Google Cloud Text to Speech - 为什么通过 Go 客户端库和 REST API 的请求之间存在延迟差异?
- doctrine-orm - 如何在 TYPO3 中注册 DQL 函数
- weblogic - 如何启用 Weblogic 托管服务器 ResolveDNSName?
- angular - 重新排序视图的子项。Nativescript Angular