Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/mercurial/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs 谷歌地图没有出现_Reactjs - Fatal编程技术网

Reactjs 谷歌地图没有出现

Reactjs 谷歌地图没有出现,reactjs,Reactjs,我正在尝试使用谷歌地图react,但是当我尝试渲染它时,什么也没有出现。我错过什么了吗 import GoogleMap from 'google-map-react'; import React, { Component } from 'react'; class GMaps extends Component { static defaultProps = { center: {lat: 59.95, lng: 30.33}, zoom: 11 }; rende

我正在尝试使用
谷歌地图react
,但是当我尝试渲染它时,什么也没有出现。我错过什么了吗

import GoogleMap from 'google-map-react';
import React, { Component } from 'react';

class GMaps extends Component {



static defaultProps = {
    center: {lat: 59.95, lng: 30.33},
    zoom: 11
  };

render() {
  return (
   <div>
    <GoogleMap
       style={{width: "100%", height: "500"}}
       defaultCenter={this.props.center}
       defaultZoom={this.props.zoom}
     />
   </div>
  )
} 


}
从“谷歌地图反应”导入谷歌地图;
从“React”导入React,{Component};
类gmap扩展组件{
静态defaultProps={
中心:{lat:59.95,lng:30.33},
缩放:11
};
render(){
返回(
)
} 
}

请检查是否正确呈现应用程序


请参阅此工作示例:

为容器div填充指定高度和宽度将解决此问题

<div style={{ height: '100vh', width: '100%' }}>
<GoogleMapReact
   defaultCenter={this.props.center}
   defaultZoom={this.props.zoom}
 />
</div>


正如《入门》中所提到的:

在这里工作得很好。你有什么错误吗。如何呈现itI?没有任何错误。是的,这很有效,知道如何获取用户当前位置吗?如果有任何浮点/绝对位置,请确保清除浮点。如果组件是默认导出,请使用GoogleMapReact或GoogleMap不起作用。只有当组件是命名的导出时,名称matters@ShubhamKhatri你说得对。我添加这个是因为我没有在codepen中导入它,我必须使用默认名称。我已更新我的答案以删除不相关的信息。是的,这很有效,知道如何获取用户当前位置吗?@joethemow您可以使用地理位置获取用户当前位置。见此: