【问题标题】:Flutter google map myLocation button iOS styleFlutter google map myLocation 按钮 iOS 风格
【发布时间】:2021-10-15 15:49:46
【问题描述】:

我在我的应用中使用了 google_maps_flutter 包,默认的 myLocation 样式在 iOS 和 Android 平台之间是不同的。

我更喜欢iOS风格,哪个按钮在右下角,圆形。 但在Android中就完全不同了,矩形并放置在右上角。

是否有可能将按钮的样式从Android更改为iOS?

【问题讨论】:

    标签: flutter google-maps dart


    【解决方案1】:

    您可以尝试创建自定义按钮。将myLocationButtonEnabled 设置为false 并在Google Maps 小部件中创建FloatingActionButton

    GoogleMap(
            mapType: MapType.hybrid,
            initialCameraPosition: _yourLocation,
            onMapCreated: (GoogleMapController controller) {
              _controller.complete(controller);
            }, ),
            myLocationEnabled: true,
           myLocationButtonEnabled: false,
            floatingActionButton: FloatingActionButton(
                backgroundColor: Colors.white,
                foregroundColor: Colors.grey,
                elevation: 5,
                onPressed: () => _getCurrentLocation(),
                child: Icon(Icons.my_location)),
          ),
        );
      }
    

    然后使用locationgeolocator 包实现自定义_getCurrentLocation() 方法。

    【讨论】:

    • 我以前试过这个。问题是:我需要显示 mylocation 蓝色圆圈,所以 myLocationButtonEnable 必须为 true。但是,如果我同时使用 _getCurrentLocation 和 myLocationButtonEnabled ,那么按下按钮时就会延迟。所以我想知道是否可以直接更改 mylocation 按钮样式来解决此问题。不过还是谢谢你的回答!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-05-08
    • 2012-03-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-08-02
    相关资源
    最近更新 更多