Download A Map
This example demonstrates how to list the road maps available on the server for download, how to download a map while indicating the download progress, and how to display the download’s finished status.
Download Progress Implementation
This is the progressListener
used to monitor the progress of obtaining the list of maps available for download from the online content store server.
The callback onStarted
is called when the map list download starts, and onCompleted
is called when the map list download is complete.
Once the map list is downloaded, the array of roadmaps is obtained from the downloaded local copy of the map list:
val models = contentStore.getStoreContentList(EContentType.RoadMap)?.first
If the array is not empty, the first item (at index 0) is obtained: val mapItem = models[0]
The progress listener is created using: val progressListener = ProgressListener.create
.
Then the download is started, and the progress listener just defined is used to monitor the progress of downloading the map at index 0 in the list of maps.
The downloaded map is stored on the device in a directory such as this: /sdcard/Android/data/com.magiclane.examplename/files/Data/Maps/
.
The progress listener also calls displayList(models)
which uses a CustomAdapter
to display a scrollable list of the maps available on the server. The list displayed is the local copy that was downloaded above.
UI and Map Integration
MainActivity
overrides onCreate()
which checks that internet access is available, and explicitly initializes the SDK, which is required for enabling use of the SDK without a map: GemSdk.initSdkWithDefaults(this)
When the internet connection is detected, or when the SDK reports that map data is ready, the loadMaps()
function is called to request the list of maps from the content store server contentStore.asyncGetStoreContentList(EContentType.RoadMap, progressListener)
The list of maps is requested, and the progressListener
shown above is passed in, to get notified when the list of maps has finished downloading. At that point, as we have already seen above, the progress listener automatically selects the first map (unless the list is empty) and downloads it automatically.
In a real world use case, the user would select which map to download.
Also, the method showStatusMessage()
will show the progress status message in a TextView
below the list.