gpt4 book ai didi

google-maps - flutter 谷歌地图。展现风格。我怎样才能得到这个工作?

转载 作者:行者123 更新时间:2023-12-03 04:42:30 25 4
gpt4 key购买 nike

由于 Google maps API 更改为基于 Widget 以及 Flutter 的某种更改,我收到以下错误:

Error: The method 'setMapStyle' isn't defined for the class 'GoogleMapController'.
我正在尝试从 .json 或 .txt 为我的 map 加载自定义样式。这是我的代码:
    SizedBox(
width: MediaQuery.of(context)
.size
.width, // or use fixed size like 200
height: 250,
child: GoogleMap(
onMapCreated: _onMapCreated,
initialCameraPosition: CameraPosition(
target: _center,
zoom: 11.0,
),
),
),
oncreate 和样式:
  void _onMapCreated(GoogleMapController controller) async {
Completer<GoogleMapController> _controller = Completer();
mapController = controller;
_setStyle(controller);
}

void _setStyle(GoogleMapController controller) async {
String value = await DefaultAssetBundle.of(context)
.loadString('assets/map_style.text');
controller.setMapStyle(value);
}
有谁知道如何解决这个问题? :/

最佳答案

我已经使用了这种方法并且它有效。

onMapCreated: (GoogleMapController controller) {
controller.setMapStyle(Utils.mapStyles);}
我将 stylr 保存在 dart 文件中
  class Utils {
static String mapStyles = '''[
{
"elementType": "geometry",
"stylers": [
{
"color": "#f5f5f5"
}
]
},
{
"elementType": "labels.icon",
"stylers": [
{
"visibility": "off"
}
]
},
{
"elementType": "labels.text.fill",
"stylers": [
{
"color": "#616161"
}
]
},
.......
]''';
}

关于google-maps - flutter 谷歌地图。展现风格。我怎样才能得到这个工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62954974/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com