Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/flutter/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Google maps google_maps_Flatter或任何其他用于Flatter的地图插件是否支持google地图的kml文件?_Google Maps_Flutter_Kml_Google Maps Flutter_Flutter Widget - Fatal编程技术网

Google maps google_maps_Flatter或任何其他用于Flatter的地图插件是否支持google地图的kml文件?

Google maps google_maps_Flatter或任何其他用于Flatter的地图插件是否支持google地图的kml文件?,google-maps,flutter,kml,google-maps-flutter,flutter-widget,Google Maps,Flutter,Kml,Google Maps Flutter,Flutter Widget,我想在Flitter中加载google地图上的kml文件。我在谷歌地图上找不到它。有没有其他插件可以在Flatter中实现这一点?已经一个月了,所以你可能已经找到了答案,但如果没有,希望这能有所帮助 您可以在flatter中运行本机代码,因此,如果您可以调整它,它应该可以工作。您需要创建一个方法通道来运行本机代码 // Run java code for KML Campus Map Overlay Future<void> _showCampusMap() async {

我想在Flitter中加载google地图上的kml文件。我在谷歌地图上找不到它。有没有其他插件可以在Flatter中实现这一点?

已经一个月了,所以你可能已经找到了答案,但如果没有,希望这能有所帮助

您可以在flatter中运行本机代码,因此,如果您可以调整它,它应该可以工作。您需要创建一个方法通道来运行本机代码

// Run java code for KML Campus Map Overlay
  Future<void> _showCampusMap() async {
    const platform = MethodChannel(**<YOUR METHOD CHANNEL>**);
    try {
      final campusMapOverlay = await platform.invokeMethod('downloadKmlLayer');
      print(campusMapOverlay);
    } on PlatformException catch (error) {
      print(error);
    }
  }
//运行KML校园地图覆盖的java代码
Future\u showCampusMap()异步{
const platform=MethodChannel(****);
试一试{
final campusMapOverlay=等待平台.invokeMethod('downloadKmlayer');
打印(campusMapOverlay);
}平台上异常捕获(错误){
打印(错误);
}
}
KML层代码可以在下面的URL中找到

尽管我已经设法让本机代码正常工作,只需显示一些文本,但我还没有弄清楚如何让KML代码正常工作。我认为问题在于不知道onPostExecute方法中的mMap是什么,但很可能还有更多我不知道的内容

    import java.io.Console;    
    import android.os.Bundle;
    import io.flutter.app.FlutterActivity;
    import io.flutter.plugins.GeneratedPluginRegistrant;
    import io.flutter.plugin.common.MethodCall;
    import io.flutter.plugin.common.MethodChannel;
    import io.flutter.plugin.common.MethodChannel.Result;
    import io.flutter.plugin.common.MethodChannel.MethodCallHandler;

    import org.xmlpull.v1.XmlPullParserException;
    import android.os.AsyncTask;
    import java.io.ByteArrayInputStream;
    import java.io.ByteArrayOutputStream;
    import java.io.IOException;
    import java.io.InputStream;
    import java.net.URL;


    public class MainActivity extends FlutterActivity {
      @Override
      protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        GeneratedPluginRegistrant.registerWith(this);

        new MethodChannel(getFlutterView(), "**<YOUR METHOD CHANNEL>**").setMethodCallHandler(new MethodCallHandler() {
          @Override
          public void onMethodCall(MethodCall call, MethodChannel.Result result) {

            if (call.method.equals("retrieveFileFromUrl")) {
              String KMLLayer = retrieveFileFromUrl();
              result.success(KMLLayer);
            }

          }
        });
      }

      private void retrieveFileFromUrl() {
        new DownloadKmlFile("**<YOUR KML LAYER>**")
                .execute();
      }

      private class DownloadKmlFile extends AsyncTask<String, Void, byte[]> {
        private final String mUrl;

        public DownloadKmlFile(String url) {
          mUrl = url;
        }

        protected byte[] doInBackground(String... params) {

          try {
            InputStream is = new URL(mUrl).openStream();
            // Log.d(TAG, "doInBackground: " + mUrl.toString());
            ByteArrayOutputStream buffer = new ByteArrayOutputStream();
            int nRead;
            byte[] data = new byte[16384];
            while ((nRead = is.read(data, 0, data.length)) != -1) {
              buffer.write(data, 0, nRead);
            }
            buffer.flush();
            return buffer.toByteArray();
          } catch (IOException e) {
            e.printStackTrace();
          }
          return null;
        }

        protected void onPostExecute(byte[] byteArr) {
          try {
            KmlLayer kmlLayer = new KmlLayer(mMap, new ByteArrayInputStream(byteArr), getApplicationContext());
            kmlLayer.addLayerToMap();
            // moveCameraToKml(kmlLayer);
          } catch (XmlPullParserException e) {
            e.printStackTrace();
          } catch (IOException e) {
            e.printStackTrace();
          }
        }
      }
    }
导入java.io.Console;
导入android.os.Bundle;
导入io.flatter.app.flatterActivity;
导入io.flatter.plugins.GeneratedPluginRegistrant;
导入io.flatter.plugin.common.MethodCall;
导入io.flatter.plugin.common.MethodChannel;
导入io.flatter.plugin.common.MethodChannel.Result;
导入io.flatter.plugin.common.MethodChannel.MethodCallHandler;
导入org.xmlpull.v1.XmlPullParserException;
导入android.os.AsyncTask;
导入java.io.ByteArrayInputStream;
导入java.io.ByteArrayOutputStream;
导入java.io.IOException;
导入java.io.InputStream;
导入java.net.URL;
公共类MainActivity扩展了公共类MainActivity{
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
生成带有(this)的pluginregistrant.registerWith;
新建MethodChannel(GetFlatterView(),“****”).setMethodCallHandler(新建MethodCallHandler()){
@凌驾
MethodCall上的公共无效(MethodCall调用,MethodChannel.Result){
if(call.method.equals(“retrieveFileFromUrl”)){
字符串Kmlayer=retrieveFileFromUrl();
结果:成功(KMLLayer);
}
}
});
}
私有void retrieveFileFromUrl(){
新下载的KMLFile(“****”)
.execute();
}
私有类下载KMLFile扩展异步任务{
私人最终字符串mUrl;
公共下载KMLFile(字符串url){
mUrl=url;
}
受保护字节[]doInBackground(字符串…参数){
试一试{
InputStream is=新URL(mUrl).openStream();
//Log.d(标记“doInBackground:+mUrl.toString());
ByteArrayOutputStream缓冲区=新建ByteArrayOutputStream();
国际nRead;
字节[]数据=新字节[16384];
而((nRead=is.read(data,0,data.length))!=-1){
写入(数据,0,nRead);
}
buffer.flush();
返回buffer.toByteArray();
}捕获(IOE异常){
e、 printStackTrace();
}
返回null;
}
受保护的void onPostExecute(字节[]byteArr){
试一试{
Kmlayer Kmlayer=newKmlayer(mMap,newbytearrayinputstream(byteArr),getApplicationContext());
kmlLayer.addLayerToMap();
//moveCameraToKml(kmlLayer);
}catch(XMLPullParseRexE){
e、 printStackTrace();
}捕获(IOE异常){
e、 printStackTrace();
}
}
}
}
你可以在这里看到更多的细节


我希望能让你走上正确的道路。

已经一个月了,所以你可能已经找到了答案,但如果你还没有找到答案,希望这能有所帮助

您可以在flatter中运行本机代码,因此,如果您可以调整它,它应该可以工作。您需要创建一个方法通道来运行本机代码

// Run java code for KML Campus Map Overlay
  Future<void> _showCampusMap() async {
    const platform = MethodChannel(**<YOUR METHOD CHANNEL>**);
    try {
      final campusMapOverlay = await platform.invokeMethod('downloadKmlLayer');
      print(campusMapOverlay);
    } on PlatformException catch (error) {
      print(error);
    }
  }
//运行KML校园地图覆盖的java代码
Future\u showCampusMap()异步{
const platform=MethodChannel(****);
试一试{
final campusMapOverlay=等待平台.invokeMethod('downloadKmlayer');
打印(campusMapOverlay);
}平台上异常捕获(错误){
打印(错误);
}
}
KML层代码可以在下面的URL中找到

尽管我已经设法让本机代码正常工作,只需显示一些文本,但我还没有弄清楚如何让KML代码正常工作。我认为问题在于不知道onPostExecute方法中的mMap是什么,但很可能还有更多我不知道的内容

    import java.io.Console;    
    import android.os.Bundle;
    import io.flutter.app.FlutterActivity;
    import io.flutter.plugins.GeneratedPluginRegistrant;
    import io.flutter.plugin.common.MethodCall;
    import io.flutter.plugin.common.MethodChannel;
    import io.flutter.plugin.common.MethodChannel.Result;
    import io.flutter.plugin.common.MethodChannel.MethodCallHandler;

    import org.xmlpull.v1.XmlPullParserException;
    import android.os.AsyncTask;
    import java.io.ByteArrayInputStream;
    import java.io.ByteArrayOutputStream;
    import java.io.IOException;
    import java.io.InputStream;
    import java.net.URL;


    public class MainActivity extends FlutterActivity {
      @Override
      protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        GeneratedPluginRegistrant.registerWith(this);

        new MethodChannel(getFlutterView(), "**<YOUR METHOD CHANNEL>**").setMethodCallHandler(new MethodCallHandler() {
          @Override
          public void onMethodCall(MethodCall call, MethodChannel.Result result) {

            if (call.method.equals("retrieveFileFromUrl")) {
              String KMLLayer = retrieveFileFromUrl();
              result.success(KMLLayer);
            }

          }
        });
      }

      private void retrieveFileFromUrl() {
        new DownloadKmlFile("**<YOUR KML LAYER>**")
                .execute();
      }

      private class DownloadKmlFile extends AsyncTask<String, Void, byte[]> {
        private final String mUrl;

        public DownloadKmlFile(String url) {
          mUrl = url;
        }

        protected byte[] doInBackground(String... params) {

          try {
            InputStream is = new URL(mUrl).openStream();
            // Log.d(TAG, "doInBackground: " + mUrl.toString());
            ByteArrayOutputStream buffer = new ByteArrayOutputStream();
            int nRead;
            byte[] data = new byte[16384];
            while ((nRead = is.read(data, 0, data.length)) != -1) {
              buffer.write(data, 0, nRead);
            }
            buffer.flush();
            return buffer.toByteArray();
          } catch (IOException e) {
            e.printStackTrace();
          }
          return null;
        }

        protected void onPostExecute(byte[] byteArr) {
          try {
            KmlLayer kmlLayer = new KmlLayer(mMap, new ByteArrayInputStream(byteArr), getApplicationContext());
            kmlLayer.addLayerToMap();
            // moveCameraToKml(kmlLayer);
          } catch (XmlPullParserException e) {
            e.printStackTrace();
          } catch (IOException e) {
            e.printStackTrace();
          }
        }
      }
    }
导入java.io.Console;
导入android.os.Bundle;
导入io.flatter.app.flatterActivity;
导入io.flatter.plugins.GeneratedPluginRegistrant;
导入io.flatter.plugin.common.MethodCall;
导入io.flatter.plugin.common.MethodChannel;
导入io.flatter.plugin.common.MethodChannel.Result;
导入io.flatter.plugin.common.MethodChannel.MethodCallHandler;
导入org.xmlpull.v1.XmlPullParserException;
导入android.os.AsyncTask;
导入java.io.ByteArrayInputStream;
导入java.io.ByteArrayOutputStream;
导入java.io.IOException;
导入java.io.InputStream;
导入java.net.URL;
公共类MainActivity扩展了公共类MainActivity{
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
生成带有(this)的pluginregistrant.registerWith;
新建MethodChannel(GetFlatterView(),“****”).setMethodCallHandler(新建MethodCallHandler()){
@凌驾
MethodCall上的公共无效(MethodCall cal)