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

xma*_*urn 4 google-maps marker google-maps-markers flutter

我正在开发一个 flutter 应用程序,尝试使用官方插件添加 Google 地图,但是,有大量的系统标记我不知道如何删除。

这些标记来自 Google 自己的数据库,但我们确实不需要这些额外的信息,它们会给我们的用户带来问题,因为用户认为这些标记来自我们自己的应用程序!大的用户体验问题。

我在课堂上找不到开关或类似的东西GoogleMap

有任何想法吗?谢谢!

系统标记

小智 15

这可以通过将自定义谷歌地图样式应用到您的谷歌地图来实现。

创建自定义谷歌地图样式。使用工具生成一个map_style.json并将其保存在您的资产文件夹中。(确保它也在 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);
  }
Run Code Online (Sandbox Code Playgroud)

在你的谷歌地图小部件中像这样实现它:

     GoogleMap(
        ...
        onMapCreated: (GoogleMapController c) {
          yourMapController = c;
          changeMapMode(yourMapController);
        },
      ),
Run Code Online (Sandbox Code Playgroud)