我依靠 flutter 中的本机代码将 .kml 覆盖加载到我的 Google 地图(修改后的 GoogleMapController.java)。
.kml 覆盖存储在此处:android/app/src/main/res/raw/borders.kml。
我在 main.dart 中调用我的覆盖层,如下所示:
Future<void> addKml(GoogleMapController mapController) async {
const MethodChannel channel = MethodChannel('flutter.native/helper');
try {
int kmlResourceId = await channel.invokeMethod('KML');
return mapController.channel.invokeMethod("map#addKML", <String, dynamic>{
'resourceId': kmlResourceId,
});
} on PlatformException catch (e) {
throw 'Unable to plot map: ${e.message}';
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的 MainActivity.kt:
class MainActivity: FlutterActivity() {
private val CHANNEL = "flutter.native/helper"
private var mapId: Int? = null
override fun onCreate(savedInstanceState: Bundle?, PersistentState: PersistableBundle?) {
super.onCreate(savedInstanceState, PersistentState)
GeneratedPluginRegistrant.registerWith(FlutterEngine(this));
}
override …Run Code Online (Sandbox Code Playgroud)