Open ebadta81 opened 2 years ago
fwiw I was wondering this too, and i dont need to call it if i do a panTo and setZoom when the map is loaded
This is just an example of using onLoad prop. It is not required at all!
This is just an example of using onLoad prop. It is not required at all!
Yes, but there is a center and zoom property in the GoogleMap object, which do nothing.
I assumed, they do something, but if I don't use onLoad with fitBounds, I see a grey rectangle.
fwiw I was wondering this too, and i dont need to call it if i do a panTo and setZoom when the map is loaded
I tried with panTo, setZoom and it is very strange. I use GoogleMap in a Mui dialog box, and for the first time I open it, it shows the map, but if i close and open it again, it shows me grey rectangle.
this is my modified onLoad code:
const onLoad = useCallback(function callback(map: google.maps.Map) {
if (lat && lng) {
console.log(`lat: ${lat} lng: ${lng}`)
map.panTo({lat: lat, lng: lng})
}
if (zoom) {
console.log(`zoom: ${zoom}`)
map.setZoom(zoom)
}
setMap(map)
}, [])
Every time, I open the dialog, I see the lat, lng and zoom text on the console, and no error message appears.
For test purposes, I put the fitBounds before the panTo, setZoom. In this case the map appears every time. :)
So this is a workaround for me.
This is just an example of using onLoad prop. It is not required at all!
This was causing my map to go to the ocean even if I call setCenter
right after/before the fitBounds
It shows me only a grey rectangle, if I don't call fitBounds(). I have center and zoom in GoogleMap props. Why is it not enough?
Also it totally ignores setZoom. Only the rectangle matters, I set in fitBounds.
This way I need to manually compute nw se coords. This is unconfortable, and wrong.
I tried without calling onLoad too.
Your Environment
os: mac
node --version v16.15.1
react version 18.2.0
@react-google-maps/api version 2.13.1