Search for an address

Learn how to find an address or place with a search bar and the .

Overview of how to search for an address

Geocoding is the process of converting address or text into a . The can search for an address or a place and perform .

In this tutorial, you use a search bar in the user interface to access the Geocoding service and search for addresses and places.

Prerequisites

Before starting this tutorial:

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

  2. Your system meets the system requirements.

Set up authentication

To access the secure used in this tutorial, you must implement using an or an account.

Create a new API key access token with privileges to access the secure resources used in this tutorial.

  1. Complete the Create an API key tutorial and create an API key with the following privilege(s):

    • Privileges
      • Location services > Basemaps
      • Location services > Geocoding
  2. Copy and paste the API Key access token into a safe location. It will be used in a later step.

Develop or Download

To complete this tutorial you have 2 options:

  1. Option 1: Develop the code or
  2. Option 2: Download the completed solution

Option 1: Develop the code

To start the tutorial, complete the Display a map tutorial. This creates a map to display the Santa Monica Mountains in California using the topographic basemap from the .

Continue with the following instructions to add a search bar to the user interface and search for an address or place using the . First, you need to set the develop credentials in your app so that your app users can access the .

Set developer credentials

To allow your app users to access , pass the developer credentials that you created in the Set up authentication step to the application's ArcGISEnvironment.

Pass your API Key access token to the ArcGISEnvironment.

  1. In the Project Navigator, click MainApp.swift.

  2. Set the ArcGISEnvironment.apiKey property with your API key access token.

    MainApp.swift
    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
            ArcGISEnvironment.apiKey = APIKey("<#YOUR-ACCESS-TOKEN#>")
    

Best Practice: The access token is stored directly in the code as a convenience for this tutorial. In a production environment we do not recommend that you store it directly in source code.

Update the map

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

  2. In the editor, change the map and viewpoint into two separate @State variables so that the viewpoint can be changed as the geocode results change.

    ContentView.swift
    55 56 57 58 59 60 61 62 63
    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
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    struct ContentView: View {
    
        @State private var map = Map(basemapStyle: .arcGISImagery)
        @State private var viewpoint: Viewpoint? = Viewpoint(
            latitude: 34.02700,
            longitude: -118.80500,
            scale: 72_000
        )
    
    
  3. Create a private class named Model of type ObservableObject and add a @StateObject variable of the Model to the ContentView. See the programming patterns page for more information on how to manage states.

    ContentView.swift
    16 17 18 19 20 21 22 23 24 25 26 27 28
    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
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    import SwiftUI
    
    import ArcGIS
    
    private class Model: ObservableObject {
    
    }
    
    struct ContentView: View {
    
        @StateObject private var model = Model()
    
    }
  4. Create a GraphicsOverlay named graphicsOverlay in the Model class. A is a container for .

    ContentView.swift
    20 21 22 23 24
    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
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    private class Model: ObservableObject {
    
        let graphicsOverlay: GraphicsOverlay
    
    }
    
  5. Lastly, add the viewpoint and graphics overlay to the .

    ContentView.swift
    88 89 90 91 92
    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
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
        var body: some View {
    
            MapView(map: map, viewpoint: viewpoint, graphicsOverlays: [model.graphicsOverlay])
    
        }
    

Add graphics

Graphics are added as a visual means to display the search result on the .

  1. Create a private property named textGraphic in the Model class. This graphic will be used to display the result's text label.

    ContentView.swift
    Expand
    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
    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
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    private class Model: ObservableObject {
    
        let graphicsOverlay: GraphicsOverlay
    
        let textGraphic: Graphic = {
            let textSymbol = TextSymbol(
                text: "",
                color: .black,
                size: 14,
                horizontalAlignment: .center,
                verticalAlignment: .bottom
            )
            textSymbol.backgroundColor = .white
            return Graphic(symbol: textSymbol)
        }()
    
    }
    
    Expand
  2. Create a private property named markerGraphic in the Model class. This graphic will be used to display the result's location.

    ContentView.swift
    Expand
    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
    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
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    private class Model: ObservableObject {
    
        let graphicsOverlay: GraphicsOverlay
    
        let textGraphic: Graphic = {
            let textSymbol = TextSymbol(
                text: "",
                color: .black,
                size: 14,
                horizontalAlignment: .center,
                verticalAlignment: .bottom
            )
            textSymbol.backgroundColor = .white
            return Graphic(symbol: textSymbol)
        }()
    
        let markerGraphic: Graphic = {
            let markerSymbol = SimpleMarkerSymbol(
                style: .square,
                color: .red,
                size: 14
            )
            return Graphic(symbol: markerSymbol)
        }()
    
    }
    
    Expand
  3. Create an init function for the Model class. Create a GraphicsOverlay with the textGraphic and markerGraphic and assign it to the model's graphics overlay. This function will be called when Model is initialized.

    ContentView.swift
    Expand
    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
    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
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    private class Model: ObservableObject {
    
        let graphicsOverlay: GraphicsOverlay
    
        let textGraphic: Graphic = {
            let textSymbol = TextSymbol(
                text: "",
                color: .black,
                size: 14,
                horizontalAlignment: .center,
                verticalAlignment: .bottom
            )
            textSymbol.backgroundColor = .white
            return Graphic(symbol: textSymbol)
        }()
    
        let markerGraphic: Graphic = {
            let markerSymbol = SimpleMarkerSymbol(
                style: .square,
                color: .red,
                size: 14
            )
            return Graphic(symbol: markerSymbol)
        }()
    
        init() {
            graphicsOverlay = GraphicsOverlay(graphics: [textGraphic, markerGraphic])
        }
    
    }
    
    Expand

Create a locator task with geocode parameters

Geocoding is implemented with a , typically created by referencing a service such as the or, for offline geocoding, by referencing locator data contained in a . Geocoding parameters can be used to fine-tune the results, such as setting the maximum number of results or requesting additional attributes in the results.

  1. Create a LocatorTask property in the Model, named locator, based on the ArcGIS geocoding service hosted by ESRI.

    ContentView.swift
    Expand
    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
    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
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    private class Model: ObservableObject {
    
        let graphicsOverlay: GraphicsOverlay
    
        let locator = LocatorTask(
            url: URL(string: "https://geocode-api.arcgis.com/arcgis/rest/services/World/GeocodeServer")!
        )
    
        let textGraphic: Graphic = {
            let textSymbol = TextSymbol(
                text: "",
                color: .black,
                size: 14,
                horizontalAlignment: .center,
                verticalAlignment: .bottom
            )
            textSymbol.backgroundColor = .white
            return Graphic(symbol: textSymbol)
        }()
    
        let markerGraphic: Graphic = {
            let markerSymbol = SimpleMarkerSymbol(
                style: .square,
                color: .red,
                size: 14
            )
            return Graphic(symbol: markerSymbol)
        }()
    
        init() {
            graphicsOverlay = GraphicsOverlay(graphics: [textGraphic, markerGraphic])
        }
    
    }
    
    Expand
  2. In the ContentView, create a private String variable named searchText with the @State property wrapper. This will hold the user input and be used to perform the geocode operation.

    ContentView.swift
    Expand
    55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
    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
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    struct ContentView: View {
    
        @StateObject private var model = Model()
    
        @State private var map = Map(basemapStyle: .arcGISImagery)
        @State private var viewpoint: Viewpoint? = Viewpoint(
            latitude: 34.02700,
            longitude: -118.80500,
            scale: 72_000
        )
    
        @State private var searchText: String = ""
    
        var body: some View {
    
            MapView(map: map, viewpoint: viewpoint, graphicsOverlays: [model.graphicsOverlay])
    
        }
    
    }
  3. Create a private, asynchronous function named geocode(with:). This function will be called when the user inputs an address.

    ContentView.swift
    Expand
    55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
    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
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    struct ContentView: View {
    
        @StateObject private var model = Model()
    
        @State private var map = Map(basemapStyle: .arcGISImagery)
        @State private var viewpoint: Viewpoint? = Viewpoint(
            latitude: 34.02700,
            longitude: -118.80500,
            scale: 72_000
        )
    
        @State private var searchText: String = ""
    
        private func geocode(with searchText: String) async throws {
    
        }
    
        var body: some View {
    
            MapView(map: map, viewpoint: viewpoint, graphicsOverlays: [model.graphicsOverlay])
    
        }
    
    }
  4. Within the new function, create GeocodeParameters, and its attributes as follows:

    • Specify which attributes to return with addResultAttributeName. * is used to return all attributes.
    • Set the maximum number of results to be returned with maxResults. In this tutorial, only return the best match by passing in 1. Results are ordered by score, so just returning the first result will return the highest scoring result.
    • Set the with outputSpatialReference. By default the output spatial reference is determined by the geocode service. For optimal performance when displaying the geocode result, ensure the returned coordinates match those of the map view by providing mapView.spatialReference as a parameter.
    ContentView.swift
    Expand
    68 69 70 71 72 73 74 75
    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
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
        private func geocode(with searchText: String) async throws {
    
            let parameters = GeocodeParameters()
            parameters.addResultAttributeName("*")
            parameters.maxResults = 1
            parameters.outputSpatialReference = map.spatialReference
    
        }
    
    Expand
  5. Perform the geocode operation by calling geocode(forSearchText:using:) and supplying the search text and the geocode parameters. The result obtained from the geocode operation will be displayed as a in the map view's .

    ContentView.swift
    Expand
    68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
    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
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
        private func geocode(with searchText: String) async throws {
    
            let parameters = GeocodeParameters()
            parameters.addResultAttributeName("*")
            parameters.maxResults = 1
            parameters.outputSpatialReference = map.spatialReference
    
            let geocodeResults = try await model.locator.geocode(forSearchText: searchText, using: parameters)
            if let firstResult = geocodeResults.first,
               let extent = firstResult.extent,
               let location = firstResult.displayLocation,
               let symbol = model.textGraphic.symbol as? TextSymbol {
                viewpoint = Viewpoint(boundingGeometry: extent)
                model.markerGraphic.geometry = location
                model.textGraphic.geometry = location
                symbol.text = firstResult.label
            }
    
        }
    
    Expand

Add a search bar to the UI

To search an address using the application, add a UI element to prompt the user for text input.

  1. In the body, add an overlay to the MapView. Set the alignment to the top, add padding all around, and set the background.

    ContentView.swift
    Expand
    88 89 90 91 92 93 94 95 96 97 98
    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
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
        var body: some View {
    
            MapView(map: map, viewpoint: viewpoint, graphicsOverlays: [model.graphicsOverlay])
    
                .overlay(alignment: .top) {
    
                    .padding(EdgeInsets(top: 60, leading: 10, bottom: 10, trailing: 10))
                    .background(.thinMaterial, ignoresSafeAreaEdges: .horizontal)
                }
    
        }
    
    Expand
  2. Within the overlay, add the following:

    • TextField: Pass in "Enter address" as the titleKey and the searchText variable as a binding for the text parameter
    • Spacer(): Add space in between the text field and button.
    • Button: Label it "Search" and using a Task method, call the geocode(with:) function and pass in searchText
    ContentView.swift
    Expand
    88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
    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
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
        var body: some View {
    
            MapView(map: map, viewpoint: viewpoint, graphicsOverlays: [model.graphicsOverlay])
    
                .overlay(alignment: .top) {
    
                    HStack {
                        TextField("Enter address", text: $searchText)
                        Spacer()
                        Button("Search") {
                            Task {
                                try await geocode(with: searchText)
                            }
                        }
                    }
    
                    .padding(EdgeInsets(top: 60, leading: 10, bottom: 10, trailing: 10))
                    .background(.thinMaterial, ignoresSafeAreaEdges: .horizontal)
                }
    
        }
    
    Expand

Run the solution

Press Command + R to run the app.

You should see a search box at the top of the map. Search for an address by entering an address and tap the Search button. The result of the search should display on the map as a red square with the address displayed on top.

Alternatively, you can download the tutorial solution, as follows.

Option 2: Download the solution

  1. Click the Download solution link under Solution and unzip the file to a location on your machine.

  2. Open the .xcodeproj file in Xcode.

Since the downloaded solution does not contain authentication credentials, you must add the developer credentials that you created in the set up authentication section.

Set developer credentials in the solution

To allow your app users to access , pass the developer credentials that you created in the Set up authentication step to the application's ArcGISEnvironment.

Pass your API Key access token to the ArcGISEnvironment.

  1. In the Project Navigator, click MainApp.swift.

  2. Set the ArcGISEnvironment.apiKey property with your API key access token.

    MainApp.swift
    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
            ArcGISEnvironment.apiKey = APIKey("<#YOUR-ACCESS-TOKEN#>")
    

Best Practice: The access token is stored directly in the code as a convenience for this tutorial. In a production environment we do not recommend that you store it directly in source code.

Run the solution

Press Command + R to run the app.

You should see a search box at the top of the map. Search for an address by entering an address and tap the Search button. The result of the search should display on the map as a red square with the address displayed on top.

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

Supported

Supported

ArcGIS Enterprise users cannot access the ArcGIS location services used by this tutorial. Instead, you must use appropriate ArcGIS Enterprise services and items. Learn more.