1

I have KML file and i want insert layer tomy googlemap in my fragment. I tried to use KmlLayer from Android-Map-Utils, but parsing file took a long time (about 2 minutes) and then draw nothing.

        KmlLayer kmlLayer = new KmlLayer(googleMap, R.drawable.crime, getActivity().getBaseContext());
        kmlLayer.addLayerToMap();
vrba99
  • 21
  • 1
  • 3

2 Answers2

0

You may find it quicker to pass the kml file and add the layer

Mark Gilchrist
  • 1,972
  • 3
  • 24
  • 44
0

The visual representation of the drawing is defined in the KML file. Every shape in the KML file has a style definition (e.g.):

<styleUrl>#Style8-multi_geometry-4-map</styleUrl>

Which is mapped to a StyleMap (containing multiple styles) or Style. The style defines what is drawn on the map, here is an example which draws a filled polygon with a border:

<Style id='Style8-polygon-3'>
    <LabelStyle>
        <scale>0.0</scale>
    </LabelStyle>
    <LineStyle>
        <color>ff666666</color>
        <width>1</width>
    </LineStyle>
    <PolyStyle>
        <color>7f0000ff</color>
        </PolyStyle>
    <BalloonStyle>
        <text>$[description]</text>
    </BalloonStyle>
</Style>

If styles are missing for the shapes in your KML file you might see nothing on the map.

Regarding the loading time, for 3MB 2 minutes seem normal to me. Under the hood is an XML parser which is not the fastest. You could look at converting the KML to GeoJSON. Tools for conversion can be found online, styling is not applied after conversion, that has to be set manually. Minify the GeoJSON to keep the filesize small.

GeoJsonLayer layer = new GeoJsonLayer(map, R.raw.crime, getContext());
layer.getDefaultPolygonStyle().setFillColor(getResources().getColor(R.color.accent));
layer.getDefaultPolygonStyle().setStrokeColor(getResources().getColor(R.color.accent));
layer.getDefaultPolygonStyle().setStrokeWidth(1);
layer.addLayerToMap();
Hansvdg
  • 121
  • 9
  • After converting from KML to GeoJsonLayer is map drawn (about 30 seconds) but without a fill color, but I need fill color, because this is a layer in which each district have of a different color ..... and my colleague works on the iPhone when he parsing and drawing to map from the same KML file about two seconds – vrba99 Sep 03 '15 at 17:55
  • Since I do not know the exact contents of your GeoJSON or KML file I cannot comment as to why the setFillColor does not fill your shapes. You can iterate over different items with layer.getFeatures() and then color them one by one. Otherwise editing the KML file and setting a style for each shape is the remaining option. – Hansvdg Sep 08 '15 at 11:40