0

I'm building an android application in which I want to show data from a KML file on a Mapfragment.

I'm using the example code from Google's documentation on the KmlLayer class. But sadly the documentation on the class is abysmal.

I'm using the following method to add the layer to the map:

private void loadKml(File file) {

    try {

        InputStream is = new BufferedInputStream(new FileInputStream(file));

        int size = is.available();

        byte[] buffer = new byte[size];

        is.read(buffer);

        Log.i("Status", "Setting KML layer.");
        KmlLayer layer = new KmlLayer(map, is, context);
        layer.addLayerToMap();

        is.close();


    } catch (IOException ex) {
        ex.printStackTrace();
        // TODO: handle error
    } catch (XmlPullParserException e) {
        // TODO: handle error
        e.printStackTrace();
    }


}

The KML file is not complicated. It has 20 connected points at the most.

No exceptions are thrown. Also no error messages are shown in logcat. And the layer is not shown on the map, what am I doing wrong here?

Willem Leuverink
  • 164
  • 3
  • 12
  • 1
    It might be your `inputStream` is empty or your KML file is invalid, can you upload your project to GitHub to demonstrate your issue? – ztan Dec 04 '15 at 23:00
  • 1
    You were right, the inputstream was faulty. Thanks for the suggestion! – Willem Leuverink Dec 06 '15 at 15:07
  • How did you solve the issue? – nPcomp Jun 12 '17 at 01:02
  • Sorry this was some time ago and I don't have access to the source anymore. If memory serves me right the only thing that I had to change in the example was the FileInputStream, but what I changed it to eludes me. – Willem Leuverink Jun 15 '17 at 08:15
  • Found the solution in an old answer. Maybe it answers your question. https://stackoverflow.com/questions/2444639/does-the-android-api-support-kml-files/34124509#34124509 – Willem Leuverink Jun 15 '17 at 08:21

0 Answers0