当我尝试使用 Google 地图加载组件时(道具已按预期传递给组件),我只是收到一条消息"Loading map..."
,但未加载带有标记的地图。控制台中也没有错误。这是组件。我在这里做错了什么?
import React, {Component} from 'react';
import {Map, InfoWindow, Marker, GoogleApiWrapper} from 'google-maps-react';
import { Constants } from './../../utils/constants';
export class MapContainer extends Component {
state = {
selectedPlace: ''
}
onMarkerClick = (e) => {
this.setState({selectedPlace: e.Name});
}
render() {
return (
<Map
google={this.props.google}
style={{width: '20vw', height: '45vh', 'top': '1.5rem'}}
containerStyle={{width: '20vw', height: '30vh'}}
initialCenter={{
lat: this.props.lat,
lng: this.props.lng
}}
zoom={15}>
{this.props.markers.length > 0 && // Rendering multiple markers for
this.props.markers.map((m) => {
return (<Marker
onClick={this.onMarkerClick}
name={this.state.selectedPlace}
position={{ lat: m.Latitude, lng: m.Longitude }}
key={m.Name} />);
})
}
{this.props.markers && // Rendering single marker for supplier details map
<Marker onClick={this.onMarkerClick}
name={this.state.selectedPlace} />
}
<InfoWindow onClose={this.onInfoWindowClose}>
<h4>{this.state.selectedPlace}</h4>
</InfoWindow>
</Map>
);
}
}
export default GoogleApiWrapper({
apiKey: (Constants.GoogleMapsApiKey),
language: "RU"
})(MapContainer)