×
Download A Map | Maps SDK for Android | General Magic Download A Map — Maps & Navigation SDKs documentation
Skip to content

Download A Map

In this guide you will learn how to get a list of the available country and region maps on the server and how to download a map for offline use.

Setup

First, get an API key token, see the Getting Started guide.

Download the Maps & Navigation SDK for Android archive file

Download the DownloadingOnboardMap project archive file or clone the project with Git

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.

Map download example Android screenshot

Map download example Android screenshot

Map download example Android screenshot

Displays a list of maps on the server available for download. Automatically downloads a map.

How it works

Android example screenshot

You can open the MainActivity.kt file to see how the list of maps is obtained from the server and displayed, and then one of the maps is downloaded.

1var models: ArrayList<ContentStoreItem>? = null
2// Get the list of maps that was retrieved in the content store.
3val result = contentStore.getStoreContentList(EContentType.RoadMap)
4if (result != null) models = result.first

In the class MainActivity : AppCompatActivity(), a private val contentStore = ContentStore() instance is created, which is then used to read the list of available maps from the server. This list of country and region road maps are stored in result.

 1if (!models.isNullOrEmpty()) {
 2  // The map items list is not empty or null.
 3  val mapItem = models[4]
 4  val itemName = mapItem.name
 5
 6  // Define a listener to the progress of the map download action.
 7  val downloadProgressListener = ProgressListener.create(
 8  onStarted = {
 9    progressBar?.visibility = View.VISIBLE
10    showToast("Started downloading $itemName.")
11  },
12  onCompleted = { _, _ ->
13    progressBar?.visibility = View.GONE
14    showToast("$itemName was downloaded.")
15  }
16  )
17  // Start downloading the first map item.
18  SdkCall.execute {
19    mapItem.asyncDownload(
20      downloadProgressListener,
21      GemSdk.EDataSavePolicy.UseDefault,
22      true
23      )
24    }
25  }

The first item in the list has index 0, so the selected mapItem = models[4] at index 4 is the 5th map in the list, Andorra in this case. A downloadProgressListener = ProgressListener.create() is defined, and onStarted and onCompleted are filled in to print a message on screen when the download starts, and another message when the download finishes.

SdkCall.execute { mapItem.asyncDownload() } then downloads the preselected map. The downloaded map is stored on the device in a directory such as this: /sdcard/Android/data/com.generalmagic.examplename/files/Data/Maps/.

Android Examples

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