Recenter view on button click does not work #36
-
i am using google-maps-react-markers which is a great library. The problem is that if I set a defaultCenter the map works correctly. only now I would like to move the view to other coordinates by clicking a button. The view then remains at the defaultCenter coordinates and therefore does not shift to the correct coordinates. In the documentation I read that you have to replace defaultCenter to center in order to do this. only then I get the following error:
and then the map is not visible, can someone help me with the right solution? my code:
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Hi @JoppeMeijers. Center and Zoom are not managed in this way. You should change them by using the methods in map ref. const zoom = {
default: 13,
in: 20,
}
const onMarkerClick = (business) => {
mapRef.current.setCenter(business.coordinates)
mapRef.current.setZoom(zoom.in)
} |
Beta Was this translation helpful? Give feedback.
Hi @JoppeMeijers. Center and Zoom are not managed in this way. You should change them by using the methods in map ref.
Example: