ArcGIS Runtime SDK for iOS version 100.15 is a long-term support release focused exclusively on bug fixes and minor updates. See the Product Life Cycle document for more information.
ArcGIS Maps SDK for Swift version 200.x is built on the proven architecture of 100.15, and is designed to leverage the latest developer framework innovations.
Go to 200.xLearn how to create and display a map with a basemap layer.
A map contains layers of geographic data. A map contains a basemap layer and, optionally, one or more data layers. You can display a specific area of a map by using a map view and setting the location and zoom level.
In this tutorial, you create and display a map of the Santa Monica Mountains in California using the topographic basemap layer.
The map and code will be used as the starting point for other 2D tutorials.
NoteFor more background information about the topics in this tutorial, visit Maps (2D) and Basemap layers in the Mapping and location services guide.
PrerequisitesBefore starting this tutorial:
You need an ArcGIS Location Platform or ArcGIS Online account.
Your system meets the system requirements.
Use Xcode to create a single view iOS app and configure it to reference the API.
Open Xcode. In the menu bar, click File > New > Project > iOS > Single View App > Next.
<your app name>
<your organization>
Add a reference to the API by following the instructions in Get the API - Configure a project.
If you downloaded the solution, get an access token and set the API key.
An API Key gives your app access to secure resources used in this tutorial.
Go to the Create an API key tutorial to obtain a new API key access token using your ArcGIS Location Platform or ArcGIS Online account. Ensure that the following privilege is enabled: Location services > Basemaps > Basemap styles service. Copy the access token as it will be used in the next step.
In Xcode, in the Project Navigator, click AppDelegate.swift.
In the editor, set the APIKey
property on the AGSArcGISRuntimeEnvironment
with your access token.
AppDelegate.swift
Expand
Use dark colors for code blocks1
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
func application(_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
AGSArcGISRuntimeEnvironment.apiKey = "YOUR_ACCESS_TOKEN"
return true
}
Warning
The access token is stored directly in the code as a convenience for this tutorial. Storing access tokens in the source code is not best practice.
A map view is a UI component that displays a map. It also handles user interactions with the map, including navigating with touch gestures. Use Xcode and the storyboard editor to add a map view to the UI and connect it to the view controller source code. Set the map view size to fill the entire iPhone display.
In the Project Navigator, click ViewController.swift.
In the editor, add an import
statement to reference the API and add an @IBOutlet
named mapView
and of type AGSMapView
. This will provide a reference to the map view that you will create in the storyboard.
ViewController.swift
Use dark colors for code blocks
15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 16 17 18 19 20 21 22 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 24 25 26 26 26 27 28 29
Add line. Add line.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
import UIKit
import ArcGIS
class ViewController: UIViewController {
@IBOutlet weak var mapView: AGSMapView!
override func viewDidLoad() {
super.viewDidLoad()
}
}
In the Project Navigator, click Main.storyboard to open the storyboard editor.
In the menu, click View > Show Library to display the object library.
In the object library browser:
uiview
or scroll down to find View.At the bottom right of the storyboard editor, click Add New Constraints. In the panel:
0
for the top, right, bottom, and left constraints.The new view expands to fill the display.
In the menu, click View > Inspectors > Show Identity Inspector. In the Inspectors panel, set Custom Class > Class to AGSMapView
.
This sets the type of the new view to AGSMapView
.
In the storyboard editor, right click on the yellow View Controller icon to display the Connections panel. Drag the mapView outlet connector to the new AGSMapView
view on the storyboard.
This connects the AGSMapView
in the storyboard to the mapView
outlet created earlier in the ViewController
class.
Use the map view to display a map centered on the Santa Monica Mountains in California. The map will contain a topographic basemap layer.
In Xcode, in the Project Navigator, click ViewController.swift.
In the editor, define a private method named setupMap()
. In setupMap()
create an AGSMap
.
ViewController.swift
Use dark colors for code blocks
19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 20 21 22 23 24 25 26 27 28 29 29 29 30 31 32 33 34 35 36 37 38 39 40 41 42 42 42 43 44 45
Add line. Add line. Add line. Add line. Add line. Add line. Add line. Add line. Add line. Add line. Add line. Add line. Add line. Add line. Add line.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
class ViewController: UIViewController {
@IBOutlet weak var mapView: AGSMapView!
private func setupMap() {
let map = AGSMap(
basemapStyle: .arcGISTopographic
)
mapView.setViewpoint(
AGSViewpoint(
latitude: 34.02700,
longitude: -118.80500,
scale: 72_000
)
)
}
override func viewDidLoad() {
super.viewDidLoad()
}
}
Set the map
property of the mapView
outlet to the new AGSMap
.
ViewController.swift
Expand
Use dark colors for code blocks23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 40 40 40 40 39 38 38 38 38
Add line.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
private func setupMap() {
let map = AGSMap(
basemapStyle: .arcGISTopographic
)
mapView.map = map
mapView.setViewpoint(
AGSViewpoint(
latitude: 34.02700,
longitude: -118.80500,
scale: 72_000
)
)
}
In the ViewController
's viewDidLoad
method, call setupMap()
once the view has loaded.
ViewController.swift
Expand
Use dark colors for code blocks41 41 41 41 41 41 41 41 41 41 41 41 41 41 41 41 41 41 41 41 41 41 41 41 41 41 41 41 41 41 41 41 41 41 41 41 41 41 41 41 41 42 43 44 45 46 47 47 47
Add line.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
override func viewDidLoad() {
super.viewDidLoad()
setupMap()
}
You need an access token to use the location services used in this tutorial.
Go to the Create an API key tutorial to obtain an access token using your ArcGIS Location Platform or ArcGIS Online account.
Ensure that the following privilege is enabled: Location services > Basemaps > Basemap styles service.
Copy the access token as it will be used in the next step.
To learn more about other ways to get an access token, go to Types of authentication.
Set your API keyIn the Project Navigator, click AppDelegate.swift.
In the editor, add an import
statement to reference the API and in the AppDelegate
's application(_:didFinishLaunchingWithOptions:)
method, set the apiKey
property on the AGSArcGISRuntimeEnvironment
with your access token.
AppDelegate.swift
Expand
Use dark colors for code blocks15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
Add line. Add line.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
import UIKit
import ArcGIS
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
AGSArcGISRuntimeEnvironment.apiKey = "YOUR_ACCESS_TOKEN"
return true
}
}
Warning
The access token is stored directly in the code as a convenience for this tutorial. Storing access tokens in the source code is not best practice.
Press Command + R to run the app.
If you are using the Xcode simulator your system must meet these minimum requirements: macOS Big Sur 11.3, Xcode 13, iOS 13. If you are using a physical device, then refer to the system requirements.
You should see a map with the topographic basemap layer centered on the Santa Monica Mountains in California. Pinch, 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:
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4