google-maps - 如何在 flutter 中更改谷歌地图 API 我的位置按钮位置?

标签 google-maps flutter

我正在使用波纹管小部件,我想将 MyLocation 按钮更改为 map View 中的底部位置

GoogleMap(

                  onMapCreated: onMapCreated,

              options: GoogleMapOptions(


                    myLocationEnabled :true, 
                    mapType: MapType.hybrid,

                  cameraPosition: CameraPosition(
                    target: LatLng(6.8814635,79.8876697),
                    zoom: 15.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,
      ),
    ));
  }

关于google-maps - 如何在 flutter 中更改谷歌地图 API 我的位置按钮位置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55273101/

相关文章:

flutter - 从 flutter 中的普通(非 Material ui) Canvas 开始

Flutter DropDownButton Popup 按钮下方 200px

javascript - 谷歌地图自定义图层与可点击标记

google-maps - 如何在谷歌地图中为一家公司添加多个位置?

javascript - 格式化回调函数的返回值

java - 带有标记的 Google Maps Android API 问题

android - 抖动错误: VM snapshot invalid and could not be inferred from settings

dart - 在 Flutter 应用中下载大型 pdf 文件

ios - iOS 中是否有 INTERNET 权限?

css - ArcGIS JS API SetOpacity 在 IE8 中不工作