Hi
I'm trying to zoom in on the marker i select, and un-zoom on deselect.
After loading all the markers i use fitBounds on the map ref to show all the markers.
I use this.state.center and this.state.zoom to change the zoom.
After using fitBounds I can't change the zoom nor the center.
If I remove fitBounds zoom and center props works well.
Is there a way to get both working :-) ?
Not sure, my best guess is you need to hook onZoomChange and onCenterChange to catch changes made by fitBounds.
Bad thing for imperative APIs.
onZoomChange is not fired at all.
I'm having the same problem. Any solutions?
I don't think center and zoom are reliable when using fitBounds (which is async)
My workaround was to modify my markers array and call fitBounds on componentWillReceiveProps
markers array to only contain that marker, and fitBounds is called and will center and zoom on the single marker.markers and fitBounds will unzoom to fit the markersconst bounds = new window.google.maps.LatLngBounds();
const coordinates = this.props.locations.map(model => {
const { latitude, longitude } = model.particulars.location.point;
const latLng = new window.google.maps.LatLng(latitude, longitude);
bounds.extend(latLng);
return latLng;
});
return (
<GoogleMap
ref={map => map && map.fitBounds(bounds)}
defaultZoom={8}
defaultCenter={{ lat: -34.397, lng: 150.644 }}
center={new google.maps.LatLng(props.latitude, props.longitude)}
>
{coordinates.map(({ lat, lng }) => {
return <Marker key={hash(lat, lng)} position={{ lat: lat(), lng: lng() }} />;
})}
</GoogleMap>
);
Most helpful comment
onZoomChangeis not fired at all.