3

I have Kml file which have some lat lngs but I don't know how to parse it in android?

I checked this link How to draw a path on a map using kml file?

but it's different. It is getting the data from the server in kml format. But I have kml file stored in assets.

Thanks in advance..

Community
  • 1
  • 1
user
  • 245
  • 1
  • 4
  • 12

1 Answers1

0

Read KML:

public String loadKMLFromAsset() {

    String kmlData = null;
    try {

        InputStream is = getAssets().open("yourKMLFile");

        int size = is.available();

        byte[] buffer = new byte[size];

        is.read(buffer);

        is.close();

        kmlData = new String(buffer, "UTF-8");


    } catch (IOException ex) {
        ex.printStackTrace();
        return null;
    }
    return kmlData;

}
Pratik Butani
  • 60,504
  • 58
  • 273
  • 437