javascript - React map 元素渲染后不显示

标签 javascript google-maps reactjs

我在 React 中找到了唯一可用的谷歌地图示例,地址为 https://github.com/StephenGrider/ReduxCastsweather项目。可以用 npm i; npm start 安装

我有https://bitbucket.org/codyc54321/anthony-project-react当您单击 map 时, map 不会显示错误,但页面上不会显示任何内容。如果你检查元素并打开主体,你确实会看到许多包含谷歌地图的 html 的 div,但没有任何可见的东西。我不设计东西,所以我不知道为什么它会是不可见的。

map 是

import React, { Component } from 'react';

class GoogleMap extends Component {

  componentDidMount() {
    new google.maps.Map(this.refs.map, {
      zoom: 12,
      center: {
        lat: this.props.lat,
        lng: this.props.lon
      }
    });
  }

  render() {
    return <div ref="map" />;
  }
}

export default GoogleMap;

最佳答案

确保 map 的父容器具有明确的高度和宽度尺寸。 map 就在那里,如果没有这些更改,它就不会显示。

关于javascript - React map 元素渲染后不显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44100381/

相关文章:

javascript - 使用 [mongoose_model_object].save() 方法时 contact.save 不是函数错误

javascript - 如何拆分输入表单并发送到Mysql

java - 如何使用适用于 Android 的 Google map API V2 获取不同语言的 map

Javascript数组映射函数保留数组先前项目的记录

javascript - React 路由器动画在 browserify 后获取意外 token

javascript - 在 IBM Watson IoT NodeJS 客户端上捕获错误

javascript - HTML/CSS : Line up multiple Label and Input fields

javascript - 如何在 mvc 的 gmap 脚本中添加我自己的位置

javascript - 使用 XML/SQL 标记将集群添加到 Google Map

css - css 中的媒体查询没有响应