Follow these steps to migrate your existing ArcGIS Runtime app to use ArcGIS location services.
This information is intended for developers who have an existing app built with one of the ArcGIS Runtime APIs and would like to update it to use ArcGIS location services. To use the services, your app must use ArcGIS Runtime version 100.10 or later. Use the current version of ArcGIS Runtime to ensure that you have access to the latest capabilities.
If your app was built with ArcGIS Runtime version 10.x, refer to the Migrate to 100.x from 10.2.x topic for help migrating to 100.x.
Authentication
To use any of the ArcGIS location services, your app must provide authentication with an access token. Access tokens define the scope and permissions available to your application.
There are three kinds of access tokens:
API key: a permanent token that grants your application access to ready-to-use services.
ArcGIS identity: a temporary token generated with OAuth 2.0 that gives your application access to the private content and ready-to-use services available to an existing ArcGIS user's account.
Application credentials: a temporary token generated with OAuth 2.0 that authorizes access to ready-to-use services.
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/*
* Copyright 2020 Esri
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/package com.example.app
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import com.esri.arcgisruntime.ArcGISRuntimeEnvironment
import com.esri.arcgisruntime.mapping.ArcGISMap
import com.esri.arcgisruntime.mapping.BasemapStyle
import com.esri.arcgisruntime.mapping.Viewpoint
import com.esri.arcgisruntime.mapping.view.MapView
import com.example.app.databinding.ActivityMainBinding
classMainActivity : AppCompatActivity() {
privateval activityMainBinding by lazy {
ActivityMainBinding.inflate(layoutInflater)
}
privateval mapView: MapView by lazy {
activityMainBinding.mapView
}
overridefunonCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(activityMainBinding.root)
setApiKeyForApp()
setupMap()
}
overridefunonPause() {
mapView.pause()
super.onPause()
}
overridefunonResume() {
super.onResume()
mapView.resume()
}
overridefunonDestroy() {
mapView.dispose()
super.onDestroy()
}
privatefunsetApiKeyForApp(){
// set your API key// Note: it is not best practice to store API keys in source code. The API key is referenced// here for the convenience of this tutorial. ArcGISRuntimeEnvironment.setApiKey("YOUR_API_KEY")
}
// set up your map here. You will call this method from onCreate()privatefunsetupMap() {
// create a map with the BasemapStyle streetsval map = ArcGISMap(BasemapStyle.ARCGIS_TOPOGRAPHIC)
// set the map to be displayed in the layout's MapView mapView.map = map
// set the viewpoint, Viewpoint(latitude, longitude, scale) mapView.setViewpoint(Viewpoint(34.0270, -118.8050, 72000.0))
}
}
This sets a global API key that will be used to access all ArcGIS location services used by your app. If needed, you can override this key by explicitly setting a different key on layers, basemaps, or any other classes that use platform location services (those that implement the ApiKeyResource interface).
Basemaps
Review the basemap layer service and the variety of basemaps available. Create a new basemap using one of the enumeration values from BasemapStyle and use it to create your ArcGISMap.
You can set an API key directly on the basemap or default to a global API key if one is set for the app.
Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
9
10
// Create a new 'topographic' basemap.val basemap = Basemap(BasemapStyle.ARCGIS_TOPOGRAPHIC)
// Optionally, set a specific API key for the basemap.// (Not required if a global API key is set) basemap.ApiKey = "YOUR_API_KEY"// Create a map that uses the basemap.val map = ArcGISMap(basemap)
Geocoding
Use the geocoding service and provide an API key, either globally for the app, or by setting it explicitly on your LocatorTask.
Routes and directions
Access to routing and directions APIs is unchanged with the new ArcGIS location services introduced with ArcGIS Platform. While authentication has always been required to access these services, you now have the ability to use these services with an API key in addition to ArcGIS identity.