flutterdartgoogle-maps-fluttergoogle-maps-flutter-web

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


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?


Solution

  • 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 */,
              ...
             ),
          ),
        );