google-maps - 谷歌地图占据了整个屏幕

标签 google-maps reactjs

我正在使用一个库,google-map-react:https://github.com/istarkov/google-map-react

我已按照自述文件中的说明进行操作, map 出现在屏幕上,但默认情况下它会占据整个屏幕,并且我无法更改它。这是我的代码。我尝试过:

 <GoogleMapReact
    defaultCenter={this.props.center}
    defaultZoom={this.props.zoom}
    style={{height: '400px', width: '400px'}}
  >

<GoogleMapReact
    defaultCenter={this.props.center}
    defaultZoom={this.props.zoom}
    size={{height: '400px', width: '400px'}}
  >

 <GoogleMapReact
    defaultCenter={this.props.center}
    defaultZoom={this.props.zoom}
    style={height: '400px', width: '400px'}
  >

我也尝试过使用百分比而不是硬编码像素。文档没有说明如何设置大小,我该怎么做?我什至尝试将其放入(来自 Bootstrap )内,但它仍然占据整个区域。如何手动设置尺寸?

最佳答案

这里的文档:

给出了一个示例,尽管我不清楚如何将其传递给 GoogleMapReact 标记:

{
  center: { lat, lng }, // current map center
  zoom: 4, // current map zoom
  bounds: { nw, se, sw... }, // map corners in lat lng
  size: { width, height... } // map size in px
}

还有这个例子:

其中宽度和高度作为 div 上的内联样式提供, map 将在其中渲染:

ReactDOM.render(
  <div style={{width: '100%', height: 400}}>
    <SimpleMap/>
  </div>,
  document.getElementById('main')
);

关于google-maps - 谷歌地图占据了整个屏幕,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43604549/

相关文章:

reactjs - 开 Jest : How to test function that calls bind(this)

javascript - 在 WebStorm 中,我可以在 JSX 的 HTML 中禁用 JavaScript 关键字的完成吗?

javascript - 谷歌地图信息窗口自动调整大小,新问题没有对代码进行更改

javascript - Google Maps API v3 地理编码

javascript - 从谷歌地图中删除折线

javascript - useState 我做错了什么?

reactjs - 如何使用 Go 提供动态创建的 URL 路径?

android - 在我的 Google Play 帐户中,应用程序登录私钥按钮被禁用

javascript - 如何在谷歌地图上以不同颜色显示路线上道路的优先级

reactjs - React 忽略 label 元素的 'for' 属性