Migrate to ArcGIS location services

Follow these steps to migrate your existing app to use ArcGIS location services.

This information is intended for developers who have an existing app and would like to update it to use ArcGIS location services. Use the current version to ensure that you have access to the latest capabilities.

Authentication

To use any of the ArcGIS location services, your app must provide authentication with an access token. Access tokens define the privileges available to your application.

There are three types of authentication that can be used to obtain an access token:

  • API key authentication: This type of authentication uses a long-lived access token to authenticate requests to location services and private content. Go to the Create an API key tutorial to obtain a new API Key access token. It is the recommended type of authentication for developers new to ArcGIS or to development in general.
  • User authentication: This generates a short-lived token via OAuth credentials, authorizing your application to access location services, content, and resources on behalf of an authenticated user.
  • App authentication: This generates a short-lived token via OAuth credentials, authorizing your application to access location services on your behalf.

Learn more about getting and using an access token in Security and authentication.

Global API key

When your app starts, you can set the api key on your ArcGISEnvironment to an API key access token. This authorizes access to all ArcGIS location services used by your app.

MainApp.swift
Use dark colors for code blocksCopy
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
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
import SwiftUI

import ArcGIS

@main
struct MainApp: App {

    init() {
        ArcGISEnvironment.apiKey = APIKey("<#YOUR-ACCESS-TOKEN#>")
    }

    var body: some SwiftUI.Scene {
        WindowGroup {
            ContentView()

                .ignoresSafeArea()

        }
    }

}

If needed, you can override this access token by explicitly setting a different access token on layers, basemaps, or any other classes that use platform location services (those that inherit APIKeyResource).

Basemaps

Review the basemap styles service and the variety of basemaps available. Create a new basemap using one of the enumeration values from Basemap.Style and use it to create your Map.

You can set an API Key access token directly on the basemap or default to a global access token, if one is set on the ArcGISEnvironment. The API Key must have the privilege Basemap styles service enabled.

Use dark colors for code blocksCopy
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
        // Creates a new 'topographic' basemap.
        let basemap = Basemap(style: .arcGISTopographic)


        // Optionally, set a specific access token directly for the basemap.
        // (Not required if an access token has been set on the ArcGISEnvironment).
        basemap.apiKey = APIKey("YOUR_ACCESS_TOKEN")


        // Creates a new map with the basemap.
        let map = Map(basemap: basemap)

Geocoding

Access to the geocoding service is available using an API Key access token, either globally for the app, or by setting it explicitly on your LocatorTask. If you are using an API key access token it must have been generated with the Geocoding privilege.

Routes and directions

Access to routing and directions APIs is unchanged with the new ArcGIS location services introduced with ArcGIS Location Platform. Authentication is required to access these services, using API key authentication or user authentication. If you are using an API key access token must have been generated with the Routing privilege.

See the Find routes and directions topic for more information.

Other services

See all the Location services available.

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