Привести KmlLayer к KmlPolygon

На моем onMapReady() Я называю мой метод initKML() но есть проблема приведения KmlPolygon.

private void initKML() {
    try {
        KmlLayer kmlLayer = new KmlLayer(mMap, R.raw.kmlfile, getApplicationContext());
        kmlLayer.addLayerToMap();
        kmlLayer.setMap(mMap);
        moveCameraToKml(kmlLayer);
    } catch (XmlPullParserException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }

}

private void moveCameraToKml(KmlLayer kmlLayer) {
    KmlContainer container = kmlLayer.getContainers().iterator().next();
    KmlPlacemark placemark = container.getPlacemarks().iterator().next();
    KmlPolygon polygon = (KmlPolygon) placemark.getGeometry().getGeometryObject();
    LatLngBounds.Builder builder = new LatLngBounds.Builder();
    for (LatLng latLng : polygon.getOuterBoundaryCoordinates()) {
        builder.include(latLng);
    }

    int width = getResources().getDisplayMetrics().widthPixels;
    int height = getResources().getDisplayMetrics().heightPixels;
    mMap.moveCamera(CameraUpdateFactory.newLatLngBounds(builder.build(), width, height, 1));
}

И это мой файл KML

<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2" xmlns:gx="http://www.google.com/kml/ext/2.2" xmlns:kml="http://www.opengis.net/kml/2.2"  xmlns:atom="http://www.w3.org/2005/Atom">
<Document>
    <name>Sendero 13 - Sámara.kml</name>
    <Style id="style5">
        <LineStyle>
            <color>73cccccc</color>
            <width>5</width>
        </LineStyle>
    </Style>
    <Placemark>
        <name>Sendero 13</name>
        <styleUrl>#style5</styleUrl>
        <LineString>
            <tessellate>1</tessellate>
            <coordinates>
                -16.726,28.266729,0 -16.725639,28.2672,0 -16.725691,28.2682,0 -16.72563,28.26866,0 -16.7257,28.26893,0 -16.726009,28.26922,0 -16.7262,28.269291,0 -16.72648,28.26927,0 -16.726198,28.269297,0 -16.726009,28.269207,0 -16.7257,28.26893,0 -16.725691,28.268841,0 -16.72629,28.26898,0 -16.7257,28.26885,0 -16.72571,28.26893,0 -16.725269,28.268681,0 -16.724951,28.2684,0 -16.72463,28.268339,0 -16.724409,28.26837,0 -16.724239,28.26856,0 -16.7239,28.26856,0 -16.722839,28.268351,0 -16.7225,28.268311,0 -16.722269,28.268339,0 -16.72159,28.268209,0 -16.72105,28.267509,0 -16.721001,28.26729,0 -16.721029,28.266951,0 -16.7209,28.266541,0 -16.72089,28.2661,0 -16.72019,28.2659,0 -16.720011,28.26577,0 -16.719801,28.265471,0 -16.719709,28.265459,0 -16.71954,28.26565,0 -16.71944,28.26586,0 -16.719259,28.26594,0 -16.71912,28.265909,0 -16.71854,28.26605,0 -16.717739,28.26651,0 -16.717461,28.266621,0 -16.717291,28.26676,0 -16.717051,28.266769,0 -16.716499,28.266939,0 -16.71604,28.267179,0 -16.715389,28.267361,0 -16.714809,28.26744100000001,0 -16.71426,28.267389,0 -16.71365,28.26726,0 -16.713539,28.267321,0 -16.713329,28.26758,0 -16.7131,28.267401,0 -16.712231,28.26744100000001,0 -16.71208,28.267309,0 -16.711781,28.2672,0 -16.711349,28.266821,0 -16.71067,28.266609,0 -16.71047,28.26647000000001,0 -16.71019,28.26639,0 -16.70974,28.26598900000001,0 -16.70957,28.2659,0 -16.709431,28.265671,0 -16.709181,28.26545,0 -16.70895,28.265329,0 -16.70857,28.26478,0 -16.707861,28.2642,0 -16.707689,28.264151,0 -16.7076,28.264059,0 -16.70837,28.26379,0 -16.70892,28.2635,0 -16.709089,28.263491,0 -16.70978,28.263651,0 -16.710409,28.26372,0 -16.711161,28.26346,0 -16.71143,28.26351,0 -16.7117,28.2635,0 -16.71225,28.263359,0 -16.7138,28.263241,0 -16.71476,28.263041,0 -16.71526,28.26301,0 -16.715919,28.263309,0 -16.716379,28.263399,0 -16.7167,28.26339,0 -16.71714,28.263309,0 -16.718031,28.263741,0 -16.719151,28.26416,0 -16.720329,28.263889,0 -16.72073,28.263849,0 -16.720961,28.26413,0 -16.72097,28.264441,0 -16.721359,28.2647,0 -16.7216,28.265079,0 -16.722099,28.265369,0 -16.7223,28.265341,0 -16.722639,28.26545,0 -16.72298,28.26549,0 -16.7246,28.266371,0 -16.725821,28.266911,0 -16.726009,28.26671,0 
            </coordinates>
        </LineString>
    </Placemark>
</Document>
</kml>

И журнал ошибок ниже;

java.lang.ClassCastException: java.util.ArrayList не может быть приведен к com.google.maps.android.kml.KmlPolygon на com.xercoo.presentation.mapRoute.MapActivity.moveCameraToKml(MapActivity.java:77) на com.xercoo.presentation.mapRoute.MapActivity.initKML(MapActivity.java:43) в com.xercoo.presentation.mapRoute.MapActivity.onMapReady(MapActivity.java:66)

0 ответов

Другие вопросы по тегам