<p>我在我的React JS页面上有一个页面,我正在尝试允许公司注册我的网站并添加他们的位置,以便其他公司前来租赁、购买等。如果可以的话,我还需要添加标记。我已经在我的页面上放置了Google地图,但是,我无法将搜索栏(<code>StandaloneSearchBox</code>)放在页面上,因为它一直处于“加载”状态。这是我的代码:</p>
<pre class="brush:php;toolbar:false;">import {useState, useEffect } from 'react'
import { GoogleMap, StandaloneSearchBox, LoadScript } from '@react-google-maps/api';
const initialState = {
company: '',
email: '',
password: '',
isMember: true,
}
const Register = () => {
const mapContainerStyle = {
height: "400px",
width: "800px"
}
const center = {
lat: -3.745,
lng: -38.523
};
const [values, setValues] = useState(initialState)
// global state and useNavigate
const handleChange = (e) => {
console.log(e.target)
}
const onSubmit = (e) => {
e.preventDefault()
console.log(e.target)
}
const handleLoad = ref => this.searchBox = ref;
const handlePlacesChanged = () => console.log(this.searchBox.getPlaces());
return (
<body class="page-template-default page page-id-13">
<header class="site-header">
<div class="container">
<h1 class="school-logo-text float-left"><a href="/landing"><strong>Direct</strong> Connection</a></h1>
<div class="site-header__util">
</div>
</div>
</header>
<div class="page-banner">
<div class="page-banner__bg-image" style={ { backgroundImage: "url('connection.jpg')" } }></div>
<div class="page-banner__content container container--narrow">
<h1 class="page-banner__title">Register</h1>
<div class="page-banner__intro">
<p></p>
</div>
</div>
</div>
我认为问题在于没有库。为了显示搜索框,必须有一个库。
const lib = ['places'];
将places设置为一个库,该库必须添加到LoadScript
代码中,其中包含您的API密钥。更新后的代码应该已经解决了这个问题: