Google Map React Component Tutorial
Quickstart
First, install the library:
npm install --save maps-google-react
or
yarn add maps-google-react
Automatically Lazy-loading Google API
The library includes a helper to wrap around the Google maps API. The ConnectApiMaps
Higher-Order component accepts a configuration object which must include an apiKey
. See lib/ConnectApi.js for all options it accepts.
; // ... Component {} apiKey: YOUR_GOOGLE_API_KEY_GOES_HEREMapContainer
Alternatively, the ConnectApiMaps
Higher-Order component can be configured by passing a function that will be called with whe wrapped component's props
and should returned the configuration object.
apiKey: propsapiKey language: propslanguage MapContainer
If you want to add a loading container other than the default loading container, simply pass it in the HOC, like so:
const LoadingContainer = <div>Fancy loading container!</div> apiKey: YOUR_GOOGLE_API_KEY_GOES_HERE LoadingContainer: LoadingContainerMapContainer
Sample Usage With Lazy-loading Google API:
; { return <Map google=thispropsgoogle mapOptions= zoom: 15 center: lat: 14013235199999999 lng: 1006985216 disableDefaultUI: true styles: featureType: 'poi.business' stylers: visibility: 'on' featureType: 'transit' elementType: 'labels.icon' stylers: visibility: 'off' > </Map> ; } apiKey: YOUR_GOOGLE_API_KEY_GOES_HEREMapContainer