Searching is a broad topic that encompasses many different use cases. For example, your users may want to find out what addresses are at a particular location, obtain a set of features according to some query, perform a free-form search for a piece of text in a dataset, and more. Using ArcGIS Runtime SDK for Java, all of these search tasks can be achieved using the API's task framework.
Working with tasks
Task classes are specifically designed to help you to efficiently extract information from ArcGIS for Server services. Any of these tasks can be executed either synchronously or asynchronously. Choose a method of execution depending on the speed and complexity of the task being executed and what level of responsiveness you require for your application. In most cases, if a user interface (UI) is involved, the asynchronous pattern is preferred, as executing a task on a separate thread will not freeze your application's UI.
While the functionality of each task varies, all of them follow the same basic principles and patterns. To allow users of your application to perform a task, complete the following five steps:
- Provide an interface for specifying the task's input and displaying the task's results.
- Instantiate the task class and pass the URL of the service or layer that the task will use to the task's constructor.
- Specify the input parameters to the task.
- Execute the task synchronously or asynchronously.
- When the task completes, process and present the results.
To help you choose the task appropriate for your needs, the following is a brief summary of search tasks.
You can find the geographic location of an address (geocode) or the address of a geographic location (reverse geocode) using a Locator. This operation can be performed using online geoprocessing services or local locator data. For more information. see the topic Search for places and addresses.
Retrieve features from a local or online map service that satisfy either an attribute and/or spatial query using the query task. The query task works with map services and feature services, feature layers and standalone tables, but not raster layers. The query task allows you to specify which attributes and/or geometries are returned. For more information, see Query the map.
The find task allows you to search one or more layers in a map for features with attribute values that match or contain an input value. The find task works with map services' feature layers and raster layers; it does not work with feature services or standalone tables. The find task allows you to specify whether a geometry is returned, though not which attributes are returned. For more information, see Find text in the map.
Return features from a local or online map service at a specific location on the map. This search can be performed using a specific geometry with a given tolerance on any number of layers in the map service. You could develop a tool to allow you to click map features and display any attributes of those features. For more information, see Identify features on the map.