Skip to main content
GuidesAPI ReferenceExamples

Online Maps Available

Estimated reading time: 2 minutes

In this guide you will learn how to list the maps available in the online content store and download a map.

Setup

  1. Get your Magic Lane API key token: if you do not have a token, see the Getting Started guide.
  2. Download the Maps & Navigation SDK for Android archive file.
  3. Download the OnlineMaps project archive file or clone the project with git. //check
  4. See the Configure Android Example guide.

Run the example

In Android Studio, from the File menu, select Sync Project with Gradle Files.

An android device should be connected via USB cable. Press SHIFT+F10 to compile, install and run the example on the android device.


The example gets and displays the list of maps available for download in the online content store, and downloads a map.

How it works

You can open the MainActivity.kt file to see how to list the available maps on the server and download a map.

How it works

// Kotlin code
SdkSettings.onConnected =
{
SdkCall.execute {
contentStore.asyncGetStoreContentList(EContentType.RoadMap.value, progressListener)
}
}

Get the list of maps available for download from the online content store server. This launches the request to get the list.

// Get the list of maps that was retrieved in the content store.
val result = contentStore.getStoreContentList(EContentType.RoadMap.value)
if (result != null) models = result.first

if (!models.isNullOrEmpty())
{
// The map items list is not empty or null.
val item = models[0]
val itemName = item.getName()

// Define a listener to the progress of the map download action.
val downloadProgressListener = ProgressListener.create(
onStarted = {
progressBar?.visibility = View.VISIBLE
Toast.makeText(
this@MainActivity,
"Started downloading $itemName.",
Toast.LENGTH_SHORT
).show()
},
onCompleted = { _, _ ->
progressBar?.visibility = View.GONE
Toast.makeText(
this@MainActivity,
"$itemName was downloaded.",
Toast.LENGTH_LONG
).show()
},
postOnMain = true
)

// Start downloading the first map item.
SdkCall.execute {
item.asyncDownload(
downloadProgressListener,
GemSdk.EDataSavePolicy.UseDefault,
true
)
}
}

This is the callback receiving the result of the list request. If the list of maps from the server is not empty, select the first map (index 0) and download it.

Android Examples

Maps SDK for Android Examples can be downloaded or cloned with Git.