我一直在使用 Webpack 和 Googlemaps 在线学习一门课程,我需要将它带到我的 Create-React-App 应用程序中,但我知道 create-react-app 不会读取带有 public/index 中的 api 键的脚本标签.html 文件。 是否有解决方法而不是使用谷歌地图 npm 包? 我真的很感激任何正确方向的提示。
这是我的带有 API_KEY 的脚本标签:
<script async defer
src="https://maps.googleapis.com/maps/api/js?key='API_KEY'">
</script>
这是我的 componentDidMount() 中的 google maps 对象:
componentDidMount(){
const {properties, activeProperty} = this.props;
const {latitude, longitude} = activeProperty;
this.map = new google.maps.Map(this.refs.map, {
center: {lat: latitude, lng: longitude},
mapTypeControl: false,
zoom: 14
});
this.createMarkers(properties);
}