- I installed react-google-map package
- I added this component
import React, { Component } from 'react';
import GoogleMapReact from 'google-map-react';
const AnyReactComponent = ({ text }) => <div>{text}</div>;
class SimpleMap extends Component {
static defaultProps = {
center: {
lat: 59.95,
lng: 30.33
},
zoom: 11
};
render() {
return (
// Important! Always set the container height explicitly
<div style={{ height: '100vh', width: '100%' }}>
<GoogleMapReact
bootstrapURLKeys={{ key:"AIzaSyAEKXIE54WnL96aA4qln5bEzU3uOGKqhyo" }}
defaultCenter={this.props.center}
defaultZoom={this.props.zoom}
>
<AnyReactComponent
lat={59.955413}
lng={30.337844}
text="My Marker"
/>
</GoogleMapReact>
</div>
);
}
}
export default SimpleMap;
- I add this script to index.html
<script async defer
src="https://maps.googleapis.com/maps/api/js?key=AIzaSECsV11t3FDisUFwLb5btHY-EWcP24uio&callback=initMap">
</script>
the error says :
Oops! Something went wrong.
This page didn't load Google Maps correctly. See the JavaScript console for technical details
The JS console show these errors :
- index.js:1 Google Maps JavaScript API error: ApiNotActivatedMapError
- Failed to load js?key=AIzaSyAECsV11t3FDisUFwLb5btHY-EWcP24uio&callback=initMap:1 ressource
- Access to fetch at 'https://maps.googleapis.com/maps/api/js?key=AIzaSyAECsV11t3FDisUFwLb5btHY-EWcP24uio&callback=initMap' from origin 'http://localhost:3001' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.