reactjs - 反应谷歌地图返回空元素_反应
问题描述
这是我的反应地图组件。
import GoogleMapReact from 'google-map-react';
this.state = {
center: {
lat: 59.95,
lng: 30.33
},
}
<div style={{ height: '100vh', width: '100%', position:"absolute" }}>
<GoogleMapReact
bootstrapURLKeys={{ key: "some token" }}
defaultCenter={this.props.center}
defaultZoom={16}
>
</GoogleMapReact>
</div>
但没有任何渲染。为什么?在github页面文档中,他们说parrent元素必须有一个绝对位置'100vh',宽度:'100%'。什么都没有显示在页面上。
解决方案
尝试这个
import GoogleMapReact from 'google-map-react'
const SomeText = ({ text }) => <div>{ text }</div>;
<div className='google-map' style={{width:'100%',height:'400px',margin:'auto'}}>
<GoogleMapReact defaultCenter={ this.props.center } defaultZoom={16}>
<SomeText lat={ this.props.center.lat } lng={ this.props.center.lng } text={ 'Here you are?' } />
</GoogleMapReact>
</div>
确保容器元素具有宽度和高度。地图将尝试填充父容器,但如果容器没有大小,地图将折叠到 0 宽度/高度。这不是 google-map-react 的要求,它通常是 google-maps 的要求。
推荐阅读
- c - strncmp() 函数与 !(strncmp()) 函数
- indexing - 如何在 MonetDB 中快速更改 (DELSERT) 表中使 DELETE 更快?
- reactjs - 尝试使用从 CDN 提供的包时,Typescript 抛出错误“未定义名称”
- python - 如何将 ROS msg 从一个 python 发布到另一个
- node.js - ElasticSearch-js { body } 未定义
- python-3.x - 按键时停止鼠标事件
- css - 如何在材质 ui makeStyles 中使用 @supports css 规则?
- java - 我在比较两个作为字符串的对象元素时遇到问题
- android - Android 模拟器在 Ubuntu 20.04 上非常慢
- c# - 错误请求被中止:无法创建 SSL/TLS 安全通道。仅在 Windows Server 2012 上