反应如何在弹出窗口中显示Google Maps反应地图?

时间:2019-05-21 01:33:33

标签: javascript reactjs popup google-maps-react

尝试在单击按钮时在弹出窗口中显示地图,当不在弹出窗口中时地图显示正常,但弹出窗口仅显示“正在加载...”,而不显示地图。感谢您的任何帮助。

export class Search extends Component {
    constructor(props) {
        super(props);

        this.state = {
          showPopup: false
        };
      }

      togglePopup() {  
        this.setState({  
             showPopup: !this.state.showPopup  
        });  
        } 

  render() {
    return (
        <div>   
            <Button onClick={this.togglePopup.bind(this)}> Click To Launch Popup</Button>  
            {this.state.showPopup ?  
            <Popup 
                    closePopup={this.togglePopup.bind(this)} 
            />  
            : null  
            }  
        </div> 
      );
  }
}

弹出窗口:

class Popup extends React.Component {  
    render() {  
  return (  
  <div className='popup'>  
  <div className='popup_inner'>  
  <Button onClick={this.props.closePopup}>close</Button> 
  <Map
    google={this.props.google}
    style= {{
        width: '50%',
        height: '50%'
    }}
    zoom={9}
    initialCenter={{lat: -27.4698, lng: 153.0251}}
    onReady={this.handleMapReady}
    >
    </Map> 
  </div>  
  </div>  
  );  
  }  
  }

我认为问题出在这里,只是不确定如何解决:

export default GoogleApiWrapper({
    apiKey: my_API_key,
    libraries: ["visualization"]
  })(Search)

0 个答案:

没有答案