Ask Your Question
3

Is it possible to modify the camera zoom point in Flutter?

asked 2023-05-19 09:52:31 +0000

huitzilopochtli gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2023-05-19 10:17:02 +0000

djk gravatar image

Yes, it is possible to modify the camera zoom point in Flutter using the CameraPosition class's zoom parameter. The zoom parameter ranges from 0.0 to 21.0, where 0.0 represents the furthest zoom level (i.e., the entire world map), and 21.0 represents the closest zoom level (i.e., street-level).

To modify the camera zoom point, you can create a new CameraPosition object with the desired zoom level and set it as the CameraPosition for your GoogleMap widget:

GoogleMap(
  initialCameraPosition: CameraPosition(
    target: LatLng(37.7749, -122.4194),
    zoom: 15.0, // Set initial zoom level here
  ),
  onMapCreated: (GoogleMapController controller) {
    // ...
  },
)

Then, you can modify the zoom level dynamically by creating a new CameraPosition object with the updated zoom level and calling the animateCamera method on your GoogleMapController:

GoogleMapController controller; // This should be set in `onMapCreated`

void _updateZoom(double newZoom) {
  CameraPosition newCameraPosition = CameraPosition(
    target: controller.cameraPosition.target,
    zoom: newZoom,
  );

  controller.animateCamera(CameraUpdate.newCameraPosition(newCameraPosition));
}
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2023-05-19 09:52:31 +0000

Seen: 14 times

Last updated: May 19 '23