Android API 支持 KML 文件吗?

发布于 2024-08-24 18:04:01 字数 124 浏览 1 评论 0原文

Android 中有没有办法将 Google Earth 中的 KML 文件加载到地图小部件中?

具体来说,我希望尽可能轻松地加载在 Google Earth 中创建的已保存形状并覆盖地图小部件。以前有人尝试过这个吗?

Is there a way in Android to load KML files from Google Earth into a map widget?

Specifically I am looking to load saved shapes created in Google Earth overtop a map widget as easily as possible. Has anybody ever tried this before?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

跨年 2024-08-31 18:04:01

这是一个老问题,但如果有人偶然发现它,这个答案可能会有一些用处。

您的意思是以编程方式将 kml 文件添加到应用程序内的地图片段上吗?
如果是这样,您可以使用此方法。

 private void loadKml(File file) {

    try( InputStream inputstream = new FileInputStream(file) ) {

        // Set kmllayer to map
        // map is a GoogleMap, context is the Activity Context

        KmlLayer layer = new KmlLayer(map, inputstream, context);

        layer.addLayerToMap();



    // Handle these errors

    } catch (FileNotFoundException e) {

        e.printStackTrace();

    } catch (IOException e) {

        e.printStackTrace();

    } catch (XmlPullParserException e) {

        e.printStackTrace();
    }

}

缺点是您几乎无法控制 KML 图层的显示方式。您可以在此处找到完整的参考:https://developers.google.com /maps/documentation/android-api/utility/kml

您还可以尝试使用 JAK 和 JAXB 将 kml 文件解析为 POJO,并以编程方式绘制该数据。如果你能让它发挥作用,那就相对无痛。 https://labs.micromata.de/projects/jak.html

It is an old question but this answer might be of some use if someone happens to stumble upon it.

Do you mean to add the kml file onto a mapfragment inside an app programmatically?
If so, you can use this method.

 private void loadKml(File file) {

    try( InputStream inputstream = new FileInputStream(file) ) {

        // Set kmllayer to map
        // map is a GoogleMap, context is the Activity Context

        KmlLayer layer = new KmlLayer(map, inputstream, context);

        layer.addLayerToMap();



    // Handle these errors

    } catch (FileNotFoundException e) {

        e.printStackTrace();

    } catch (IOException e) {

        e.printStackTrace();

    } catch (XmlPullParserException e) {

        e.printStackTrace();
    }

}

The downside is that you have little to no control as to how the kml layer is displayed. You can find a complete reference here: https://developers.google.com/maps/documentation/android-api/utility/kml

You can also try to parse the kml file to a POJO using JAK and JAXB and draw that data programmatically. If you can get it to work it is relatively painless. https://labs.micromata.de/projects/jak.html

鱼忆七猫命九 2024-08-31 18:04:01

看起来您可以在地图上加载 KML 文件,但没有像从 libkml 获得的编程访问权限。

It looks like you can load KML files on a map but there is no programmatic access like you would get from libkml.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文