-
Notifications
You must be signed in to change notification settings - Fork 30.3k
[google_maps_flutter] initialCameraPosition with bounding #29181
Copy link
Copy link
Open
Labels
P2Important issues not at the top of the work listImportant issues not at the top of the work listcustomer: crowdAffects or could affect many people, though not necessarily a specific customer.Affects or could affect many people, though not necessarily a specific customer.p: mapsGoogle Maps pluginGoogle Maps pluginpackageflutter/packages repository. See also p: labels.flutter/packages repository. See also p: labels.team-ecosystemOwned by Ecosystem teamOwned by Ecosystem teamtriaged-ecosystemTriaged by Ecosystem teamTriaged by Ecosystem team
Metadata
Metadata
Assignees
Labels
P2Important issues not at the top of the work listImportant issues not at the top of the work listcustomer: crowdAffects or could affect many people, though not necessarily a specific customer.Affects or could affect many people, though not necessarily a specific customer.p: mapsGoogle Maps pluginGoogle Maps pluginpackageflutter/packages repository. See also p: labels.flutter/packages repository. See also p: labels.team-ecosystemOwned by Ecosystem teamOwned by Ecosystem teamtriaged-ecosystemTriaged by Ecosystem teamTriaged by Ecosystem team
I am using the google-maps package for flutter and I need to fit multiple markers. I tried to fix it by calculating the bounding box and the zoom level by myself, but this didn't quite work as expected. Sometimes, the camera is too far out.
Since a few versions, there is the ability to animate to a
LatLngBounds, which would work and zoom correct. I tried to call the following, when map was created:controller.animateCamera(CameraUpdate.newLatLngBounds(LatLngBounds( southwest: const LatLng(-38.483935, 113.248673), northeast: const LatLng(-8.982446, 153.823821), ), 10));Sometimes this is working, but sometimes I get the following platform-exception:
Error using newLatLngBounds(LatLngBounds, int): Map size can't be 0. Most likely, layout has not yet occured for the map view. Either wait until layout has occurred or use newLatLngBounds(LatLngBounds, int, int, int) which allows you to specify the map's dimensions.I also tried to achieve this by adding the
cameraTargetBoundsproperty to theGoogleMap-Widget, but as I have seen in another issue, this will not zoom to fit correctly, and I do not want to bound the camera position, I only want to fit it at init.Is there a solution or a workaround? Or do I have to wait, until it is officially supported?