React-google-maps: Center value changes on its own on different zoom value

Created on 26 Feb 2018  Â·  2Comments  Â·  Source: tomchentw/react-google-maps

Hi! :)

I ran into strange behavior with center and zoom props (I also tried defaultZoom and defaultCenter props). Here is the code of render function of my component:

render() {
        const { comrades, profileGeoCoordinates } = this.props
        console.log('center', profileGeoCoordinates)

        return <div>
            <GoogleMap
                options={mapOptions}
                center={profileGeoCoordinates}
                zoom={2}
                onCenterChanged={() => {
                    console.log('onCenterChanged', { lat: this.mapRef.getCenter().lat(), lng: this.mapRef.getCenter().lng() })
                }}
                onIdle={() => {
                    console.log('onIdle', { lat: this.mapRef.getCenter().lat(), lng: this.mapRef.getCenter().lng() })
                    console.log('onIdle', { zoom: this.mapRef.props.zoom })
                }}
                ref={ref => this.mapRef = ref }
            >
                {comrades.map(this.mapComrades)}
            </GoogleMap>
        </div>
    }

I pass profileGeoCoordinates from store and when zoom value < 2 it's rendering with correct center:
zoom < 2

but when zoom value > 2 center value changes on it's own:
zoom > 2#1
zoom > 2#2

It seems somehow connected with InfoBoxes that I render in this.mapComrades — if they all fit into the map center do not change, else it's different on each zoom, but this is only an assumption.

What I'm missing? What should I do to get a correct center of the map on the first render?

Most helpful comment

Thank you! :D

All 2 comments

We're facing the same issue here! Turns out it's by design, and you can turn it off. I scanned through past issues and found this -- resolved the issue for us: #716

Thank you! :D

Was this page helpful?
0 / 5 - 0 ratings

Related issues

0x1bitcrack3r picture 0x1bitcrack3r  Â·  3Comments

bansalvks picture bansalvks  Â·  3Comments

timkraut picture timkraut  Â·  3Comments

tahir-masood1 picture tahir-masood1  Â·  4Comments

julienvincent picture julienvincent  Â·  3Comments