您可以通过将自定义的谷歌地图样式应用于谷歌地图来实现此目标。
要创建自定义的谷歌地图样式,请使用此工具生成一个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);
},
),