【问题标题】:Exporting GPS data from a database into GPX or KML in android将 GPS 数据从数据库导出到 android 中的 GPX 或 KML
【发布时间】:2013-04-17 16:46:09
【问题描述】:

我正在开发一个应用程序,它可以跟踪 gps 坐标并将它们存储到数据库中的单独表中。我想将表格中的 gps 数据导出为 GPX 或 KML 格式。我真的找不到任何教程或解释如何做到这一点。我应该将纬度和经度坐标写入标签之间的文件吗?或者我的文件需要满足什么要求?

我实现的代码:

        File directory = Environment.getExternalStorageDirectory();
        if (directory.canWrite()){
            File kmlFile = new File(directory, "" + table + ".kml");
            FileWriter fileWriter = new FileWriter(kmlFile);
            BufferedWriter outWriter = new BufferedWriter(fileWriter);

            outWriter.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
                    "\n <kml xmlns=\"http://www.opengis.net/kml/2.2\">" +
                    "\n <Document>" + "\n");
                    for (int i = 0; i<latArrayList.size();i++){
                        outWriter.write("<Placemark>" + 
                                        "\n <name>" + i + "</name>" +
                                        "\n <description> </description>" +
                                        "\n <Point>" +
                                        "\n <coordinates>" + latArrayList.get(i) + "," + lonArrayList.get(i) + "</coordinates>" +
                                        "\n </Point>" +
                                        "\n </Placemark>" + "\n");
                    }
            outWriter.write("</Document>" + 
                            "\n </kml>");
            outWriter.close();

还有一个我加载到谷歌地图并显示错误坐标的 kml 文件示例:

<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<Document>
<Placemark>
<name>0</name>
<description> </description>
<Point>
<coordinates>46.09312,18.22501
</coordinates>
</Point>
</Placemark>
<Placemark>
<name>1</name>
<description> </description>
<Point>
<coordinates>46.09317333333333,18.22474833333333
</coordinates>
</Point>
</Placemark>
<Placemark>
<name>2</name>
<description> </description>
<Point>
<coordinates>46.093138333333336,18.22449
 </coordinates>
</Point>
</Placemark> </Placemark>
</Document>
</kml>

【问题讨论】:

    标签: android gps kml gpx


    【解决方案1】:

    不确定您是否还有问题...

    可在此处找到 KML 文件的要求: https://developers.google.com/kml/documentation/kmlreference

    这里是 GPX 的 xml 架构: http://www.topografix.com/GPX/1/1/gpx.xsd

    我没有“否定”你,但我猜有些人这样做了,因为这些搜索非常简单;)

    您确实是对的,您必须将其写入文件,然后您可以通过意图将其发布到 Google 地球。

    祝你好运

    【讨论】:

    • 谢谢,上周我实现了一些代码,我的应用程序可以导出到一个 kml 文件,但是当我将它加载到谷歌地图时它显示错误的坐标,我检查了一个 kml 验证器,结果是有效的我想我必须以某种方式转换纬度和经度?我更新了我的问题
    • 你正在导出 Lat, lon 并且你应该使用 LON, LAT: Change: "\n " + latArrayList.get(i) + "," + lonArrayList.get(i) + "" 到:"\n " + lonArrayList.get(i) + "," + latArrayList.get(i) + ""
    猜你喜欢
    • 1970-01-01
    • 2023-03-10
    • 1970-01-01
    • 1970-01-01
    • 2013-06-17
    • 2014-08-05
    • 1970-01-01
    • 2023-03-29
    • 1970-01-01
    相关资源
    最近更新 更多