Taylor Austin
Taylor Austin

Reputation: 6027

How to make sure map is loaded with google-map-react

I am using google-map-react and need to have access to the map.

I access the ref through doing something like:

<GoogleMap ref={ref => this.map = ref} />

When I call the ref on componentDidMount() like so this.map.map_ it returns null because the map has not loaded yet. I need a way to access this when the component mounts.

Upvotes: 0

Views: 2147

Answers (1)

Tomasz Mularczyk
Tomasz Mularczyk

Reputation: 36219

I think you can use onGoogleApiLoaded:

handleGoogleApiLoaded = ({map, maps}) => {
  map...
}

<GoogleMap  
  onGoogleApiLoaded={this.handleGoogleApiLoaded}
  yesIWantToUseGoogleMapApiInternals
/>

Upvotes: 1

Related Questions