Skip to content

[google_maps_flutter] initialCameraPosition with bounding #29181

@ItsPierre

Description

@ItsPierre

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 cameraTargetBounds property to the GoogleMap-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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work listcustomer: crowdAffects or could affect many people, though not necessarily a specific customer.p: mapsGoogle Maps pluginpackageflutter/packages repository. See also p: labels.team-ecosystemOwned by Ecosystem teamtriaged-ecosystemTriaged by Ecosystem team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions