Can't set zoom or initial center on GoogleMap component.
See original GitHub issueI updated the package and applied the method in the example on the NPM doc, setting center and zoom props but they don’t seem to have any effect.
<GoogleMap
mapContainerStyle={containerStyle}
center={{
lat: 46.13033,
lng: -90.346771,
}}
zoom={1}
options={{
styles: isDark ? darkMapStyle : lightMapStyle,
}}
onLoad={onLoad}
onUnmount={onUnmount}
></GoogleMap>
Your Environment
os: windows
node --version
react version 16.13.1
webpack version
@babel version
@react-google-maps/api version 1.13.0
How is it behave?
initial center is in another coordinate, and zoom is not the zoom I set.
How should it behave correctly?
Map should have the center position entered, and the zoom.
basic implementation of incorrect behavior in codesandbox.com
Issue Analytics
- State:
- Created 3 years ago
- Comments:6
Top Results From Across the Web
Can't change center of the map #579 - GitHub
Same, can't change center of map on state or props update. Zoom works, though. This can't be a react component if the doesn't...
Read more >google maps api initial zoom error - Stack Overflow
If you only have one marker, don't use fitBounds, use .setCenter (on the coordinates of the marker, .setZoom (to your desired zoom level)....
Read more >Controlling Zoom and Pan | Maps JavaScript API
The following map demonstrates the default behavior for map interactions with a map instantiated with only the zoom and center options defined.
Read more >A Beginner's Guide to google-map-react | by Matt Croak Code
I still want to maintain the original defaultZoom (the user can zoom in and out by clicking the plus and minus symbols on...
Read more >React Google Maps Style Guide
Everything inside a component will be mounted automatically on the map And ... or center and zoom have not been set then the...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
As @candrescastel mentioned already, you should check your onLoad function! I had the same issue because I copy pasted the whole Maps component at first.
This is the answer OP. I had the same issue, this is how I fixed it. Thank you @joobacca