Display a map from a mobile map package

Learn how to display a from a .

display a map from a mobile map package

In this tutorial you will display a fully interactive from a . The map contains a and and does not require a network connection.

Prerequisites

Before starting this tutorial:

  1. You need an ArcGIS Location Platform or ArcGIS Online account.

  2. Your system meets the system requirements.

Steps

Open the Xcode project

  1. To start the tutorial, complete the Display a map tutorial or download and unzip the solution.

  2. Open the .xcodeproj file in Xcode.

Add a mobile map package

You will add a to your Xcode project. To get an .mmpk file, you can complete the Create a mobile map package tutorial or download its solution.

Once you have the mobile map package:

  1. In Xcode's app menu, click File > Add Files to "...".
  2. Navigate to and select the .mmpk file. If you used the tutorial solution, it will be named MahouRivieraTrails.mmpk.
  3. Choose Options, select the Copy items if needed checkbox, and ensure the project target is selected in Add to targets. Click Add.

Open the mobile map package and display a map

Select a from the maps contained in a , and display it in a map view. Use the AGSMobileMapPackage class to access the mobile map package, and load it to read its contents.

  1. In Xcode, in the Project Navigator, click ViewController.swift.

  2. In the editor, modify the setupMap() function to create an AGSMobileMapPackage referencing the you added to the project.

    ViewController.swift
    24 25 26 27 28 29 30
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
        private func setupMap() {
    
            let mobileMapPackage = AGSMobileMapPackage(
                name: "MahouRivieraTrails"
            )
    
        }
    
  3. Load the AGSMobileMapPackage and check that it loads without error. Display the first in the package in the map view.

    ViewController.swift
    24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
        private func setupMap() {
    
            let mobileMapPackage = AGSMobileMapPackage(
                name: "MahouRivieraTrails"
            )
    
            mobileMapPackage.load { [weak self] error in
                if let error = error {
                    print("Error loading the mmpk: \(error.localizedDescription)")
                    return
                }
    
                if let map = mobileMapPackage.maps.first {
                    self?.mapView.map = map
                }
            }
    
        }
    
  4. Press Command + R to run the app.

You should see a of trail heads, trails, and parks for the area south of the Santa Monica mountains. You will be able to pinch (to zoom and rotate), drag, and double-tap the map view to explore the map.

What's next?

Learn how to use additional API features, ArcGIS location services, and ArcGIS tools in these tutorials:

Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.

You can no longer sign into this site. Go to your ArcGIS portal or the ArcGIS Location Platform dashboard to perform management tasks.

Your ArcGIS portal

Create, manage, and access API keys and OAuth 2.0 developer credentials, hosted layers, and data services.

Your ArcGIS Location Platform dashboard

Manage billing, monitor service usage, and access additional resources.

Learn more about these changes in the What's new in Esri Developers June 2024 blog post.

Close