Closed fvisticot closed 2 years ago
Hello @fvisticot, I can't manager to reproduce it. You get a null value on getVisibleRegion() ? It might be a flutter_google_maps bug.
Hi,
I have the same issue using google_maps_cluster_manager 0.2.0 and google_maps_flutter 1.0.2. I have to use a delay.
onMapCreated: (GoogleMapController controller) {
if (_mapController.isCompleted == false) {
_mapController.complete(controller);
}
Future.delayed(Duration(milliseconds: 100)).then((value) => _clusterManager.setMapController(controller));
},
I am still having this issue on v3.0.0+1 (Flutter: version 3.0.1). The tricky part is that it appears to be a race condition, so it doesn't always happen.
I wanted to share a solution which appears to work every time.
onMapCreated: (GoogleMapController controller) async {
if (!_controller.isCompleted) {
_controller.complete(controller);
controller.getVisibleRegion().then((value) => _clusterManager.setMapId(controller.mapId));
}
}
It seems the _updateMarkers functions is called on the onMapCreated / setMapController call. This call is then trigerring the getMarkers function from the clusterManager class. In this method, the _mapController.getVisibleRegion is called.
But the current Visible region does not seems updated / available at this time.
To make it works, I'm obliged to add a delay before calling the _manager.setMapController(controller);
Any idea / solution ?