如何在颤抖中更改Google Map API的“我的位置”按钮位置?

时间:2019-03-21 02:55:00

标签: google-maps flutter

我正在使用波纹管小部件,我想将“我的位置”按钮更改为我的地图视图中的底部位置

GoogleMap(

                  onMapCreated: onMapCreated,

              options: GoogleMapOptions(


                    myLocationEnabled :true, 
                    mapType: MapType.hybrid,

                  cameraPosition: CameraPosition(
                    target: LatLng(6.8814635,79.8876697),
                    zoom: 15.0,),
                  ),
    ),

3 个答案:

答案 0 :(得分:1)

使用GoogleMap小部件的填充属性

return Stack(
  children: <Widget>[
    GoogleMap(
      onMapCreated: _onMapCreated,
      initialCameraPosition: CameraPosition(
        target: _center,
        zoom: 11.0,
      ),
      mapType: _currentMapType,
      markers: _markers,
      onCameraMove: _onCameraMove,
      myLocationEnabled: true,
      padding: EdgeInsets.only(top: 40.0,),
    ),[enter image description here][1]
  ],
);

image 1: without padding

image 2: with padding

答案 1 :(得分:0)

我找到了解决方案。我创建了FAB按钮来更改“我的位置”按钮

GoogleMap(
        mapType: MapType.hybrid,
        initialCameraPosition: _kGooglePlex,
        onMapCreated: (GoogleMapController controller) {
          _controller.complete(controller);
        },
        myLocationEnabled: true,
      ),
      floatingActionButton: FloatingActionButton.extended(
        onPressed: _currentLocation,
        label: Text('My Location'),
        icon: Icon(Icons.location_on),
      ),
    );
  }

还要设置_currentLocation方法来调用我的位置

void _currentLocation() async {
   final GoogleMapController controller = await _controller.future;
   LocationData currentLocation;
   var location = new Location();
   try {
     currentLocation = await location.getLocation();
     } on Exception {
       currentLocation = null;
       }

    controller.animateCamera(CameraUpdate.newCameraPosition(
      CameraPosition(
        bearing: 0,
        target: LatLng(currentLocation.latitude, currentLocation.longitude),
        zoom: 17.0,
      ),
    ));
  }

答案 2 :(得分:-1)

只需在顶部添加填充! 就我而言;

padding: EdgeInsets.only(top: 155.0),