Find address

View inQMLC++
View on GitHub
Sample viewer app

Find the location for an address.

screenshot

Use case

A user can input a raw address into your app's search bar and zoom to the address location.

How to use the sample

For simplicity, the sample comes loaded with a set of suggested addresses. Choose an address from the suggestions or submit your own address to show its location on the map in a callout.

How it works

  1. Create a LocatorTask using the URL to a locator service.
  2. Set the GeocodeParameters for the locator task and specify the geocode's attributes.
  3. Get the matching results from the GeocodeResult using locatorTask::geocodeWithParameters(addressString, geocodeParameters).
  4. Create a Graphic with the geocode result's location and store the geocode result's attributes in the graphic's attributes.
  5. Show the graphic in a GraphicsOverlay.

Relevant API

  • GeocodeParameters
  • GeocodeResult
  • LocatorTask

About the data

This sample uses the World Geocoding Service.

Tags

address, geocode, locator, search

Sample Code

FindAddress.qmlFindAddress.cppFindAddress.h
                                                                                                                                                                                                   
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
// [WriteFile Name=FindAddress, Category=Search]
// [Legal]
// Copyright 2016 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
// http://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.
// [Legal]

import QtQuick 2.6
import QtQuick.Controls 2.2
import QtQuick.Layouts 1.3
import Esri.Samples 1.0
import Esri.ArcGISRuntime.Toolkit 100.11

FindAddressSample {
    id: findAddressSample
    width: 800
    height: 600

    // add a mapView component
    MapView {
        id: mapView
        anchors.fill: parent
        objectName: "mapView"

        Callout {
            id: callout
            borderColor: "lightgrey"
            borderWidth: 1
            calloutData: mapView.calloutData
            maxWidth: findAddressSample.width * 0.75
            leaderPosition: leaderPositionEnum.Automatic
            accessoryButtonHidden: true
        }
    }

    onShowCallout: {
        callout.showCallout();
    }

    onHideCallout: {
        if (callout.visible)
            callout.dismiss();
    }

    // search bar for geocoding
    Column {
        anchors {
            fill: parent
            margins: 10
        }
        Rectangle {
            color: "#f7f8fa"
            border {
                color: "#7B7C7D"
            }
            radius: 2
            width: parent.width
            height: childrenRect.height

            GridLayout {
                width: parent.width
                columns: 3
                TextField {
                    Layout.margins: 5
                    Layout.fillWidth: true
                    id: textField
                    font.pixelSize: 14
                    placeholderText: "Type in an address"
                    selectByMouse: true

                    Keys.onEnterPressed: geocodeAddress();
                    Keys.onReturnPressed: geocodeAddress();

                    function geocodeAddress() {
                        findAddressSample.geocodeAddress(textField.text);
                        suggestView.visible = false;
                        Qt.inputMethod.hide();
                    }
                }

                Rectangle {
                    Layout.margins: 5
                    width: height
                    height: textField.height
                    color: "#f7f8fa"
                    visible: textField.length === 0
                    enabled: visible
                    Image {
                        anchors.fill: parent
                        source: "qrc:/Samples/Search/FindAddress/ic_menu_collapsedencircled_light_d.png"
                        MouseArea {
                            anchors.fill: parent
                            onClicked: {
                                textField.focus = true;
                                suggestView.visible = !suggestView.visible;
                            }
                        }
                    }
                }

                Rectangle {
                    Layout.margins: 5
                    width: height
                    color: "transparent"
                    height: textField.height
                    visible: textField.length !== 0
                    enabled: visible
                    Image {
                        anchors.fill: parent
                        source: "qrc:/Samples/Search/FindAddress/ic_menu_closeclear_light_d.png"

                        MouseArea {
                            anchors.fill: parent
                            onClicked: {
                                textField.text = "";
                                if (callout.visible)
                                    callout.dismiss();
                                clearGraphics();
                            }
                        }
                    }
                }
            }
        }

        // show a drop down of suggested locations
        ListView {
            id: suggestView
            height: 300
            width: textField.width
            visible: false
            clip: true
            model: geocodeSuggestions
            delegate: Component {
                Rectangle {
                    id: rect
                    width: parent.width
                    height: 25
                    color: "#f7f8fa"

                    Rectangle {
                        anchors {
                            top: parent.top;
                            left: parent.left;
                            right: parent.right;
                            topMargin: -5
                            leftMargin: 20
                            rightMargin: 20
                        }
                        color: "darkgrey"
                        height: 1
                    }

                    Text {
                        text: name
                        anchors {
                            fill: parent
                            leftMargin: 5
                        }

                        font.pixelSize: 14
                    }

                    MouseArea {
                        anchors.fill: parent
                        onClicked: {
                            textField.text = name;
                            suggestView.visible = false;
                            findAddressSample.geocodeAddress(name);
                            Qt.inputMethod.hide();
                        }
                    }
                }
            }
        }
    }

    ListModel {
        id: geocodeSuggestions
        ListElement { name: "277 N Avenida Caballeros, Palm Springs, CA" }
        ListElement { name: "380 New York St, Redlands, CA 92373" }
        ListElement { name: "Београд" }
        ListElement { name: "Москва" }
        ListElement { name: "北京" }
    }
}

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