如何设置缩放级别google_maps_flutter

kxeu7u2r  于 2023-04-22  发布在  Flutter
关注(0)|答案(3)|浏览(153)

我正在使用google_maps_flutter包,当按下myLocationButton时,其缩放级别被设置为我上次的缩放级别。我想在按下myLocationButton时重置缩放级别。
这是谷歌Map的代码;

GoogleMap(
                      padding: EdgeInsets.only(bottom: _mapBottomPadding),
                      mapType: MapType.normal,
                      initialCameraPosition: _baseLocation,
                      myLocationButtonEnabled: true,
                      myLocationEnabled: true,
                      
                      zoomControlsEnabled: true,
                      zoomGesturesEnabled: true,
                      // minMaxZoomPreference: const MinMaxZoomPreference(12, 14),
                      polylines: _polylineSet,
                      markers: _markersSet,
                      onMapCreated: (GoogleMapController controller) async {
                        if (!_controller.isCompleted) {
                          //first calling is false
                          //call "completer()"
                          _controller.complete(controller);
                          // setState(() {});
                        } else {
                          //other calling, later is true,
                          //don't call again completer()
                        }
                        // _controller.complete(controller);
                        _googleMapController = controller;

                        // Set Initial Camera Position
                        setCameraPosition(
                            position: locationData.getCurrentAddress.position
                                as Position);
                        setMapBounds();
                        setState(() {});
                      },
                    ),

以前设置相机位置时,变焦卡在最后一个变焦级别上,我想在单击myLocationButton时将其静止。
getString();方法调用设置缩放,这取决于Map边界,并调用下面的代码,这可能会导致一个高缩放级别和缩放级别持续调用后,当我点击myLocationButton。

_googleMapController!
          .animateCamera(CameraUpdate.newLatLngBounds(latLngBounds, 70));

如何在设置相机动画后重置缩放级别?

mznpcxlj

mznpcxlj1#

如果有帮助的话,你可以试试这个。

double zoomValue=14.0;

         LatLng   mapCenter = new LatLng("your latitude", "your longitude");
    
    initialCameraPosition: CameraPosition(
                      target: mapCenter,
                      zoom: zoomValue,
                    ),
cbeh67ev

cbeh67ev2#

试试这个

GoogleMap(
  zoomGesturesEnabled: true,
  tiltGesturesEnabled: false,
  onCameraMove:(CameraPosition cameraPosition){
     print(cameraPosition.zoom);
  },
zpjtge22

zpjtge223#

set zoomValue = 3;
LatLng   mapCenter = new LatLng("your latitude", "your longitude");

initialCameraPosition: CameraPosition(
                  target: mapCenter,
                  zoom: zoomValue,
                ),

相关问题