在颤振谷歌地图自定义中心位置按钮

时间:2019-02-03 10:39:54

标签: google-maps google-maps-api-3 dart flutter google-maps-api-2

我正在使用google_maps_flutter: ^0.0.3+3

我如何删除默认的方形按钮的中心位置,仍然保持了蓝点的当前位置?

如果不可能,如何对其进行自定义?

enter image description here

3 个答案:

答案 0 :(得分:2)

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

myLocationButtonEnabled: false,
myLocationEnabled: true,

使用google_maps_flutter:^ 0.5.13

答案 1 :(得分:0)

就目前的情况而言,这是不可能的,唯一可行的解​​决方法是设计您的UI以阻止它。

答案 2 :(得分: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))),
                ),
              ),
            ),