Create, save, and preview a KML multi-track captured from a location data source.

Use case
When capturing location data for outdoor activities such as hiking or skiing, it can be useful to record and share your path. This sample demonstrates how you can collect individual KML tracks during a navigation session, then combine and export them as a KML multi-track.
How to use the sample
Tap “Record Track” to start recording your current path on the simulated trail. Tap “Stop Recording” to end recording and capture a KML track. Repeat these steps to capture multiple KML tracks in a single session. Tap the save button to convert the recorded tracks into a KML multi-track and save it to a local .kmz file. Then, use the picker to select a track from the saved KML multi-track. Tap the Delete button to remove the local file and reset the sample.
How it works
- Create a
Mapwith a basemap style and aGraphicsOverlayto display the path geometry for your navigation route. - Create a
SimulatedLocationDataSourceto drive theLocationDisplay. - As you receive
Locationupdates, add each point to a list ofKMLTrackElementobjects while recording. - Once recording stops, create a
KMLTrackusing one or moreKMLTrackElementobjects. - Combine one or more
KMLTrackobjects into aKMLMultiTrack. - Save the
KMLMultiTrackinside aKMLDocument, then export the document to a.kmzfile. - Load the saved
.kmzfile into aKMLDatasetand locate theKMLDocumentin the dataset’srootNodes. From the document’schildNodes, get theKMLPlacemarkand retrieve theKMLMultiTrackgeometry. - Retrieve the geometry of each track in the
KMLMultiTrackby iterating through the list of tracks and obtaining the respectiveKMLTrack.geometry.
Relevant API
- KMLDataset
- KMLDocument
- KMLMultiTrack
- KMLPlacemark
- KMLTrack
- KMLTrackElement
- LocationDisplay
- SimulatedLocationDataSource
Tags
export, hiking, KML, KMZ, multi-track, record, track