Can't change the view to new coordinates of Google maps in React without throwing an error

84 Views Asked by At

for a project i am using google-maps-react-markers which uses google-maps-react. 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 image 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:

TypeError: Cannot read properties of null (reading 'getNorthEast')

and then the map is not visible, can someone help me with the right solution?

my map Code:

import GoogleMap from 'google-maps-react-markers'

  const [ChangeCenter, setChangeCenter] = useState({ lat: 50.6866452, lng: 5.004696 })
  const [ChangeZoom, setChangeZoom] = useState(4)

<GoogleMap
        apiKey="API_KEY_HERE"
        defaultCenter={{ lat: 52.0885534, lng: 6.2159387}}
        defaultZoom={7}
        options={mapOptions}
        mapMinHeight="800px"
          center={ChangeCenter}
          zoom={ChangeZoom}
          yesIWantToUseGoogleMapApiInternals
                    onGoogleApiLoaded={onGoogleApiLoaded}
                
                >
                    {Business.map(({ lat, lng, name }, index) => (
                        <Marker key={index} lat={lat} lng={lng} markerId={name} onClick={onMarkerClick} className="marker" />
                    ))}


                </GoogleMap>

So if a button is clicked on a button, the view must be adjusted with the new coordinates from ChangeCenter

0

There are 0 best solutions below