Reputation: 3238
When I'm trying to load component with Google Maps, (props was passed to the component as expected), I'm just getting a message saying "Loading map..."
but a map with markers was not loaded. No errors in the console as well. Here is the component. What I'm doing wrong here?
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)
Upvotes: 3
Views: 5150
Reputation: 17546
In your codesandbox demo, you are exporting your app component, where you need to render it.
export default GoogleApiWrapper({
apiKey: "",
language: "RU"
})(App);
const rootElement = document.getElementById("root");
ReactDOM.render(<App />, rootElement);
Here you are rendering the app component which is not wrapped by GoogleApiWrapper
HOC.
Instead of exporting the wrapped app, render it as follows:
App = GoogleApiWrapper({
apiKey: "",
language: "RU"
})(App);
const rootElement = document.getElementById("root");
ReactDOM.render(<App />, rootElement);
Upvotes: 5
Reputation: 7105
try setting the width and height of the map in pixels
style={{width: '200px', height: '450px', 'top': '1.5rem'}}
Upvotes: 0