这是我先前回答的改进版本
我刚刚测试了您的代码,其中包含许多错误,未定义和未使用的变量!因此,您可以改用以下代码,这很简单(这将使您解决当前问题并显示地图!)
首先,安装必要的库:
npm install --save google-map-react
npm install --save prop-types
然后,您可以复制下面的全部内容:
import React, { Component } from 'react';
import GoogleMapReact from 'google-map-react';
const AnyReactComponent = ({ text }) => <div>{text}</div>;
class MyClass extends Component {
constructor(props){
super(props);
}
render() {
return (
<GoogleMapReact
defaultCenter={this.props.center}
defaultZoom={this.props.zoom}
style={{height: '300px'}}
>
<AnyReactComponent
lat={59.955413}
lng={30.337844}
text={'Google Map'}
/>
</GoogleMapReact>
);
}
}
MyClass.defaultProps = {
center: {lat: 59.95, lng: 30.33},
zoom: 11
};
export default MyClass;