作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
由于 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/
leaflet:一个开源并且对移动端友好的交互式地图 JavaScript 库 中文文档: https://leafletjs.cn/reference.html 官网(英文): ht
我是一名优秀的程序员,十分优秀!