React-google-maps: Question: how to get the current zoom level?

Created on 6 Oct 2015  路  7Comments  路  Source: tomchentw/react-google-maps

I need it to calculate the radius of an overlayview component I have in the map.
Any ideas how to get it?
Thanks a lot for this project!!

Most helpful comment

@adamryvola No problem at all. Great to see always new people learning react :) Please close this issue if you think it is resolved.

Update: Issue is already closed actually ;P

All 7 comments

Awesome. Thanks!

Please, can you explain me, why this.refs.gmap is undefined in componentDidMount? I would like to access bounds of map and calculate something.

export default class Map extends Component {

    componentDidMount() {
        console.log('GMAP: ' + this.refs.gmap);
    }

    render() {
        return (
            <GoogleMapLoader
                containerElement = {
                    <div style={{height: '300px', width: '100%'}} />
                }
                googleMapElement = {
                    <GoogleMap
                        ref={(googleMap) => this.gmap = googleMap}
                        defaultZoom={9}
                        defaultCenter={{ lat: this.props.markers[0].position.lat, lng: this.props.markers[0].position.lng }}
                        center={{ lat: this.props.markers[0].position.lat, lng: this.props.markers[0].position.lng }}>
                            {this.props.markers.map((marker, index) => {
                                return (<Marker {...marker} />);
                            })}
                    </GoogleMap>
                }
            />
        )
    };
}

@adamryvola please check the usage of refs on react documentation.

I believe the ref is undefined because the component passed in googleMapElement is not yet mounted in the dom, therefore the ref is available yet after the first render.

The ref is available only after this setState fires.

Soooo stupid question from me, thank you for your time :)
(I am React newbie)

@adamryvola No problem at all. Great to see always new people learning react :) Please close this issue if you think it is resolved.

Update: Issue is already closed actually ;P

Was this page helpful?
0 / 5 - 0 ratings

Related issues

manoj150283 picture manoj150283  路  3Comments

madbean picture madbean  路  3Comments

SyedSaifAli picture SyedSaifAli  路  3Comments

PaulieScanlon picture PaulieScanlon  路  3Comments

timkraut picture timkraut  路  3Comments