在Flutter Google地图中自定义中心位置按钮

9

我正在使用 google_maps_flutter: ^0.0.3+3

如何删除默认的正方形按钮以将位置居中,并仍保留蓝点表示的当前位置?

如果不可能,如何自定义它?

enter image description here


你如何改变“我的位置按钮”的位置? - Sampath Wijesinghe
3个回答

12

在GoogleMap对象上设置以下属性:

myLocationButtonEnabled: false,
myLocationEnabled: true,

使用 google_maps_flutter 库:^0.5.13


1
目前来看这是不可能的,唯一的解决方法是设计您的用户界面以阻止它。

0
我通过添加这个函数解决了这个问题。
 void setInitialLocation() async {
    currentLocation = await location.getLocation();
    destinationLocation = LOC.LocationData.fromMap({
      "latitude": currentLocation.latitude,
      "longitude": currentLocation.longitude
    });
    CameraPosition cPosition = CameraPosition(
      zoom: CAMERA_ZOOM,
      tilt: CAMERA_TILT,
      bearing: CAMERA_BEARING,
      target: LatLng(currentLocation.latitude, currentLocation.longitude),
    );
    final GoogleMapController controller = await _controller.future;
    controller
        .animateCamera(CameraUpdate.newCameraPosition(cPosition))
        .then((value) {
      setState(() {
        isCameraMoved = false;
      });
    });
  }

并将此小部件添加到 googleMap 下的堆栈中:

Align(
              alignment: Alignment.topRight,
              child: Container(
                height: 60,
                width: 60,
                padding: EdgeInsets.all(10.0),
                child: FloatingActionButton(
                  backgroundColor: Colors.white,
                  heroTag: 'recenterr',
                  onPressed: () {
                    setInitialLocation();
                  },
                  child: Icon(
                    Icons.my_location,
                    color: Colors.grey,
                  ),
                  shape: RoundedRectangleBorder(
                      borderRadius: BorderRadius.circular(10.0),
                      side: BorderSide(color: Color(0xFFECEDF1))),
                ),
              ),
            ),

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接