thats my first question here, so be patient please.
I'm studying java for Android development and I'm stuck for weeks now in one problem:
I just can't import a simple KML file in my aplication!
I tried kmlLayer, I put the file inside my devide as a input stream and nothing works for me. (Using the code which transform a string (where my file was in my device) to a InputStream with the encoding "utf-8")
So guys, somehow how can I import this polygon .kml?
<?xml version="1.0" encoding="utf-8" ?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<Document id="root_doc">
<Schema name="Extra_31_168_366" id="Extra_31_168_366">
<SimpleField name="Name" type="string"></SimpleField>
</Schema>
<Folder><name>Extra_31_168_366</name>
<Placemark>
<name>Zona Extra a levantar</name>
<Style><LineStyle><color>FF232323</color><width>0.737006</width></LineStyle><PolyStyle><fill>0</fill></PolyStyle></Style>
<MultiGeometry><Polygon><outerBoundaryIs><LinearRing><coordinates>1.04761446057425,43.1864681306065 1.04740371376916,43.186733854839 1.04859489136319,43.1875310275366 1.04966695119782,43.1877875888645 1.05063821908219,43.1884015034707 1.0513254369249,43.1888596486991 1.05327713559821,43.1889879293631 1.05492645842072,43.1892170019774 1.05634670862899,43.1890520696951 1.05765700398243,43.1895835181601 1.05871073800792,43.1907655328496 1.05776695883726,43.1951179125201 1.06452918240956,43.1965839772512 1.06447420498214,43.195631035176 1.06418099203592,43.1933403090336 1.06093732381831,43.1920391765848 1.05740044265448,43.1885939244666 1.05425298493486,43.18868097206 1.05134834418633,43.1879479396945 1.04761446057425,43.1864681306065</coordinates></LinearRing></outerBoundaryIs></Polygon></MultiGeometry>
</Placemark>
</Folder>
</Document></kml>
Right now I'm doing almost manual like that: Excel, world and putting this code inside my OnMapReady(GoogleMap googleMap):
PolygonOptions rectOptions = new PolygonOptions()
.add(new LatLng(43.1864681306065,1.04761446057425), new LatLng(43.186733854839,1.04740371376916), new LatLng(43.1875310275366,1.04859489136319), new LatLng(43.1877875888645,1.04966695119782), new LatLng(43.1884015034707,1.05063821908219), new LatLng(43.1888596486991,1.0513254369249), new LatLng(43.1889879293631,1.05327713559821), new LatLng(43.1892170019774,1.05492645842072), new LatLng(43.1890520696951,1.05634670862899), new LatLng(43.1895835181601,1.05765700398243), new LatLng(43.1907655328496,1.05871073800792), new LatLng(43.1951179125201,1.05776695883726), new LatLng(43.1965839772512,1.06452918240956), new LatLng(43.195631035176,1.06447420498214), new LatLng(43.1933403090336,1.06418099203592), new LatLng(43.1920391765848,1.06093732381831), new LatLng(43.1885939244666,1.05740044265448), new LatLng(43.18868097206,1.05425298493486), new LatLng(43.1879479396945,1.05134834418633), new LatLng(43.1864681306065,1.04761446057425));
googleMap.addPolygon(rectOptions);
You can add KML layer to the map by creating an instance of the KmlLayer class first. There are two (2) ways to instantiate a KmlLayer:
KmlLayer layer = new KmlLayer(getMap(), R.raw.kmlFile, getApplicationContext());
KmlLayer layer = new KmlLayer(getMap(), kmlInputStream, getApplicationContext());
After you have created a KmlLayer, call addLayerToMap() to add the imported data onto the map.
layer.addLayerToMap();
For more information, you may refer to the Maps SDK for Android KML Importing Utility