简体   繁体   中英

How can I use the KML or geojson to display in List view?

I have been working with osmbonus library and osmdroid library tutorial. I have download the KML and json file in my sd card and now I want to list all the information in list view.

like:
name = xyz school
amenity = school
addr:street = abc
opening_hours : Su-Fr 22:00-04:00

The kml file is in format:

<Placemark id="mId">
<Point>
<coordinates>85.0960383,27.6345759,0.0 </coordinates>
</Point>
<ExtendedData>
<Data name="addr:postcode"><value>44100</value></Data>
<Data name="name:en"><value>Palung Modern English Secondary School</value></Data>
<Data name="amenity"><value>school</value></Data>
<Data name="addr:street"><value>Tribhuvan Highway</value></Data>
<Data name="opening_hours"><value>Su-Fr 22:00-04:00</value></Data>
</ExtendedData>
</Placemark>

I have use the code like this to store the file

//file at storage/sdcard0/kml
            mKmlDocument.saveAsKML(mKmlDocument.getDefaultPathForAndroid("my_route.kml"));
// Loading and saving of GeoJSON content
            mKmlDocument.saveAsGeoJSON(mKmlDocument.getDefaultPathForAndroid("my_route.json"));

Assuming you know Android ListView mechanisms:

Access to the placemark extended data. Your placemark is the unique feature inside your KML document, so:

KmlPlacemark placemark = (KmlPlacemark)mKmlDocument.mKmlRoot.mItems.get(0);
HashMap<String, String> extendedData = placemark.mExtendedData;

Then parse its extendedData (see KmlFeature.getExtendedDataAsText source code if you need an example), and populate your ListView with that.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM