google_maps_flutter - programmatically set rotation to 0 (bearing to north)

99 views Asked by At

When I create the GoogleMap widget I can set:

initialCameraPosition: CameraPosition(
                    target: _initialCameraPosition,
                    zoom: 12.0,
                    bearing: 0.0
                  ),

but after the user changes the rotation, how can I set the bearing to 0.0 again?

1

There are 1 answers

1
offworldwelcome On BEST ANSWER

Use the GoogleMap.onMapCreated callback to store a reference to the GoogleMapController parameter it has.

GoogleMap(
      onMapCreated: (controller) => /* store the controller in state */,
      ...
    );

Then, use it to set the camera position:

controller.animateCamera(
      CameraUpdate.newCameraPosition(
         CameraPosition(
          bearing: /* set your desired bearing */,
          ...
         ),
      ),
    );