Flutter + Google Maps:如何删除系统标记?

3
我正在开发一个Flutter应用程序,尝试使用官方插件添加Google地图,但是有大量系统标记我不知道如何删除。
这些标记来自Google自己的数据库,但我们真的不需要那些额外的信息,它们会给我们的用户带来问题,因为用户认为这些标记来自我们自己的应用程序!这是一个很大的用户体验问题。
我在GoogleMap类中找不到任何开关或类似的东西。
有什么想法吗?谢谢!

System markers

1个回答

13

您可以通过将自定义的谷歌地图样式应用于谷歌地图来实现此目标。

要创建自定义的谷歌地图样式,请使用此工具生成一个map_style.json并将其保存在您的assets文件夹中。(确保它也在pubspec.yaml中被引用)。

  //this is the function to load custom map style json
  void changeMapMode(GoogleMapController mapController) {
    getJsonFile("assets/map_style.json")
        .then((value) => setMapStyle(value, mapController));
  }
  
  //helper function
  void setMapStyle(String mapStyle, GoogleMapController mapController) {
    mapController.setMapStyle(mapStyle);
  }
  
  //helper function
  Future<String> getJsonFile(String path) async {
    ByteData byte = await rootBundle.load(path);
    var list = byte.buffer.asUint8List(byte.offsetInBytes,byte.lengthInBytes);
    return utf8.decode(list);
  }

在您的 Google 地图小部件中实现如下:

     GoogleMap(
        ...
        onMapCreated: (GoogleMapController c) {
          yourMapController = c;
          changeMapMode(yourMapController);
        },
      ),

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接