如何获取kml文件的坐标 [英] How to get coordinates of kml file android

查看:1626
本文介绍了如何获取kml文件的坐标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想接收kml文件中点的坐标. 我创建了一个接收坐标的对象,但是找不到从文件中获取坐标的方法.

I want to receive the coordinates of the points that are in the kml file. I created a object that receives the coordinates but I can not find how to take them from the file.

到目前为止已完成的示例:
(点数为132,但我将其缩短为可以在此处显示.)

An example of what has been done so far:
(The amount of points is 132, but I shortened it to be able to present here.)

Kml文件:

<LinearRing>
                <coordinates>
                    34.79991805485883,32.070779943443,0
                    34.799829164854,32.07080649750882,0
                    34.79971023480251,32.07083335300256,0
                    34.79959122858838,32.07086022634235,0
                    34.79947508289758,32.07091343448649,0
                    34.79935881388468,32.07096669690968,0
                    34.79923664471844,32.07096729415576,0
                    34.79912177286835,32.07104658864036,0
                </coordinates>
<LinearRing>

在代码中:

   int i =0; 
   for (KmlContainer containers : kmlLayer.getContainers()) {
       poly[i] =new PointPoly(containers);
       i++;
     }

该代码不起作用. 希望能有所帮助.

The code does not work. Would appreciate help.

推荐答案

List<LatLng> points = new ArrayList<>();
for (KmlContainer c : kmlLayer.getContainers()) {
    for (KmlPlacemark p : c.getPlacemarks()) {
        KmlGeometry g = p.getGeometry();
        if (g.getGeometryType().equals("LineString")) {
            points.addAll((Collection<? extends LatLng>) g.getGeometryObject());
        }
    }
}

GeometryType在您的kml文件中可以不同,例如"LinearRing".但是从根本上来说,这对我来说是有效的代码.

GeometryType can be different on your kml file, like "LinearRing". But basicaly this is working code for me.

这篇关于如何获取kml文件的坐标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆