Reputation: 71
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.
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 file:
<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>
In code:
int i =0;
for (KmlContainer containers : kmlLayer.getContainers()) {
poly[i] =new PointPoly(containers);
i++;
}
The code does not work. Would appreciate help.
Upvotes: 0
Views: 2330
Reputation: 1390
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 can be different on your kml file, like "LinearRing". But basicaly this is working code for me.
Upvotes: 1
Reputation: 28767
First make sure you got the String containing the coordinates.
(the text between the <coordinates>
tag)
Then use
String[] coords3d = coordStr.split(" ");
to split into an array of lon,lat,altitude string. Loop over that array and split each string with
String[] coordLatLonAltitude = coord.split(",");
to split into separate latitude, longitude and altitude values.
Upvotes: 1