java.lang.Object
com.esri.arcgisruntime.tasks.geocode.LocatorTask
All Implemented Interfaces:
ApiKeyResource, RemoteResource, Loadable

public final class LocatorTask extends Object implements Loadable, RemoteResource, ApiKeyResource
A task used to convert an address to a point (geocode) or vice-versa (reverse geocode). An address includes any type of information that distinguishes a place. Also allows address suggestions to be generated character-by-character as a user types.

A Locator involves finding matching locations for a given address. Reverse-geocoding is the opposite and involves finding corresponding addresses for a given location.

A LocatorTask can be created for an online geocoding service or as an offline locator using data stored locally.

Since:
100.0.0
  • Property Details

  • Constructor Details

    • LocatorTask

      public LocatorTask(String uri)
      Constructs an online or offline LocatorTask.

      An online LocatorTask uses an online geocoding service and its URI consists of the web address of the service, for example:

       LocatorTask loc = new LocatorTask("http://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer");
       

      An offline LocatorTask uses data stored locally and its URI consists of the absolute path to the ".loc" file, for example:

       LocatorTask loc = new LocatorTask("/data/locators/SanFranciscoLocator.loc");
       
      Parameters:
      uri - the URI of an online geocoding service or a ".loc" file in local storage
      Throws:
      IllegalArgumentException - if uri is null or empty
      Since:
      100.0.0
  • Method Details

    • setCredential

      public void setCredential(Credential credential)
      Sets the credential used to authenticate the user with this task.
      Specified by:
      setCredential in interface RemoteResource
      Parameters:
      credential - the credential used to authenticate the user with this task
      Since:
      100.0.0
    • getCredential

      public Credential getCredential()
      Gets the credential used to authenticate the user with this task.
      Specified by:
      getCredential in interface RemoteResource
      Returns:
      the credential, or null if there is none
      Since:
      100.0.0
    • setRequestConfiguration

      public void setRequestConfiguration(RequestConfiguration requestConfiguration)
      Sets configuration parameters used for network requests sent using this task. The global RequestConfiguration is used if no RequestConfiguration is set.
      Specified by:
      setRequestConfiguration in interface RemoteResource
      Parameters:
      requestConfiguration - object containing the parameters to use
      Since:
      100.0.0
    • getRequestConfiguration

      public RequestConfiguration getRequestConfiguration()
      Gets the RequestConfiguration object in use by this task.
      Specified by:
      getRequestConfiguration in interface RemoteResource
      Returns:
      the RequestConfiguration object, or null if none has been set
      Since:
      100.0.0
      See Also:
    • getUri

      public String getUri()
      Gets the URI of this task. This is the URI used to instantiate the object.
      Specified by:
      getUri in interface RemoteResource
      Returns:
      the URI of this task
      Since:
      100.0.0
    • getLocatorInfo

      public LocatorInfo getLocatorInfo()
      Gets information about this LocatorTask. LocatorInfo is available only if the task has been loaded.
      Returns:
      information about this LocatorTask, or null if it is not loaded yet
      Since:
      100.0.0
    • geocodeAsync

      public ListenableFuture<List<GeocodeResult>> geocodeAsync(String searchText)
      Executes an asynchronous geocode operation to find location candidates for a given address. The result is an unmodifiable List of GeocodeResult objects.

      This method uses default values for various parameters that can be specified by the alternative method geocodeAsync(String, GeocodeParameters).

      Parameters:
      searchText - a String containing an address (such as "380 New York St" or "380 New York St, Redlands, California 92373") or the name of a point of interest (such as "Disneyland")
      Returns:
      a ListenableFuture for tracking when the operation is done and getting the result; also allows cancellation
      Throws:
      IllegalArgumentException - if searchText is null or empty
      Since:
      100.0.0
    • geocodeAsync

      public ListenableFuture<List<GeocodeResult>> geocodeAsync(String searchText, GeocodeParameters parameters)
      Executes an asynchronous geocode operation to find location candidates for a given address. The result is an unmodifiable List of GeocodeResult objects.
      Parameters:
      searchText - a String containing an address (such as "380 New York St" or "380 New York St, Redlands, California 92373") or the name of a point of interest (such as "Disneyland"). Also may be empty.
      parameters - an object containing parameters for the geocode operation
      Returns:
      a ListenableFuture for tracking when the operation is done and getting the result; also allows cancellation
      Throws:
      IllegalArgumentException - if searchText is null, or if parameters is null
      Since:
      100.0.0
    • geocodeAsync

      public ListenableFuture<List<GeocodeResult>> geocodeAsync(Map<String,String> searchValues)
      Executes an asynchronous geocode operation to find location candidates for a given multi-line address. The result is an unmodifiable List of GeocodeResult objects.

      For example, if the search attributes (see LocatorInfo.getSearchAttributes()) for this LocatorTask include attributes with the following names: Street, City, State, and ZIP, you could provide searchValues containing names of "Street" and "ZIP" and values of "380 New York St" and "92373".

      This method uses default values for various parameters that can be specified by the alternative method geocodeAsync(Map, GeocodeParameters).

      Parameters:
      searchValues - a Map containing attribute names and values for the input address
      Returns:
      a ListenableFuture for tracking when the operation is done and getting the result; also allows cancellation
      Throws:
      IllegalArgumentException - if searchValues is null or empty
      Since:
      100.0.0
    • geocodeAsync

      public ListenableFuture<List<GeocodeResult>> geocodeAsync(Map<String,String> searchValues, GeocodeParameters parameters)
      Executes an asynchronous geocode operation to find location candidates for a given multi-line address. The result is an unmodifiable List of GeocodeResult objects.

      For example, if the search attributes (see LocatorInfo.getSearchAttributes()) for this LocatorTask include attributes with the following names: Street, City, State, and ZIP, you could provide searchValues containing names of "Street" and "ZIP" and values of "380 New York St" and "92373".

      Parameters:
      searchValues - a Map containing attribute names and values for the input address
      parameters - an object containing parameters for the geocode operation
      Returns:
      a ListenableFuture for tracking when the operation is done and getting the result; also allows cancellation
      Throws:
      IllegalArgumentException - if searchValues is null or empty, or parameters is null
      Since:
      100.0.0
    • geocodeAsync

      public ListenableFuture<List<GeocodeResult>> geocodeAsync(SuggestResult suggestResult)
      Executes an asynchronous geocode operation to find location candidates for a result obtained from a call to one of the suggestAsync methods. The result of the geocode operation is an unmodifiable List of GeocodeResult objects.

      This method uses default values for various parameters that can be specified by the alternative method geocodeAsync(SuggestResult, GeocodeParameters).

      Parameters:
      suggestResult - a SuggestResult object returned by a call to one of the suggestAsync methods
      Returns:
      a ListenableFuture for tracking when the operation is done and getting the result; also allows cancellation
      Throws:
      IllegalArgumentException - if suggestResult is null
      Since:
      100.0.0
      See Also:
    • geocodeAsync

      public ListenableFuture<List<GeocodeResult>> geocodeAsync(SuggestResult suggestResult, GeocodeParameters parameters)
      Executes an asynchronous geocode operation to find location candidates for a result obtained from a call to one of the suggestAsync methods. The result of the geocode operation is an unmodifiable List of GeocodeResult objects.
      Parameters:
      suggestResult - a SuggestResult object returned by a call to one of the suggestAsync methods
      parameters - an object containing parameters for the geocode operation
      Returns:
      a ListenableFuture for tracking when the operation is done and getting the result; also allows cancellation
      Throws:
      IllegalArgumentException - if suggestResult or parameters is null
      Since:
      100.0.0
      See Also:
    • reverseGeocodeAsync

      public ListenableFuture<List<GeocodeResult>> reverseGeocodeAsync(Point location)
      Executes an asynchronous reverse geocode operation to find address candidates for a given location. The result is an unmodifiable List of GeocodeResult objects. Note: it is a List to allow future expansion; currently reverse geocode operations return only one location.

      This method uses default values for various parameters that can be specified by the alternative method reverseGeocodeAsync(Point, ReverseGeocodeParameters).

      Parameters:
      location - the Point at which to search for the closest address
      Returns:
      a ListenableFuture for tracking when the operation is done and getting the result; also allows cancellation
      Throws:
      IllegalArgumentException - if location is null
      Since:
      100.0.0
    • reverseGeocodeAsync

      public ListenableFuture<List<GeocodeResult>> reverseGeocodeAsync(Point location, ReverseGeocodeParameters parameters)
      Executes an asynchronous reverse geocode operation to find address candidates for a given location. The result is an unmodifiable List of GeocodeResult objects. Note: it is a List to allow future expansion; currently reverse geocode operations return only one location.
      Parameters:
      location - the Point at which to search for the closest address
      parameters - an object containing parameters for the reverse geocode operation
      Returns:
      a ListenableFuture for tracking when the operation is done and getting the result; also allows cancellation
      Throws:
      IllegalArgumentException - if location or parameters is null
      Since:
      100.0.0
    • suggestAsync

      public ListenableFuture<List<SuggestResult>> suggestAsync(String searchText)
      Executes an asynchronous suggest operation to fetch suggestions for a given search text. The result is an unmodifiable List of SuggestResult objects.

      Geocoding suggestions provide a mechanism for implementing character-by-character auto-complete. Using a text input and optional SuggestParameters, suggested addresses can be quickly found and presented to the user. Suggestions are not limited to addresses; they can also be used for POIs (Points of Interest). To return a focused set of suggestions, use SuggestParameters.setPreferredSearchLocation(Point) or SuggestParameters.setSearchArea(Geometry). Using SuggestParameters#setPreferredSearchLocation(Point) is similar to how ArcGIS Pro limits the suggestions returned.

      This method uses default values for various parameters that can be specified by the alternative method suggestAsync(String, SuggestParameters).

      Parameters:
      searchText - a text string entered by a user
      Returns:
      a ListenableFuture for tracking when the operation is done and getting the result; also allows cancellation
      Throws:
      IllegalArgumentException - if searchText is null or empty
      Since:
      100.0.0
    • suggestAsync

      public ListenableFuture<List<SuggestResult>> suggestAsync(String searchText, SuggestParameters parameters)
      Executes an asynchronous suggest operation to fetch suggestions for a given search text. The result is an unmodifiable List of SuggestResult objects.

      Geocoding suggestions provide a mechanism for implementing character-by-character auto-complete. Using a text input and optional SuggestParameters, suggested addresses can be quickly found and presented to the user. Suggestions are not limited to addresses; they can also be used for POIs (Points of Interest). To return a focused set of suggestions, use SuggestParameters.setPreferredSearchLocation(Point) or SuggestParameters.setSearchArea(Geometry). Using SuggestParameters.setPreferredSearchLocation(Point)} is similar to how ArcGIS Pro limits the suggestions returned.

      Parameters:
      searchText - a text string entered by a user
      parameters - an object containing parameters for the suggest operation
      Returns:
      a ListenableFuture for tracking when the operation is done and getting the result; also allows cancellation
      Throws:
      IllegalArgumentException - if searchText is null or empty, or if parameters is null
      Since:
      100.0.0
    • getApiKey

      public String getApiKey()
      Description copied from interface: ApiKeyResource
      Gets the API key to access API key enabled services and resources in ArcGIS Online.

      An API key is a unique key used to authorize access to specific services and resources in ArcGIS Online. It is also used to monitor access to those services. An API key is created and managed in the ArcGIS developer dashboard and is tied to a specific ArcGIS account.

      In addition to setting an API key at a global level for your application using ArcGISRuntimeEnvironment.setApiKey(String), you can call ApiKeyResource.setApiKey(String) on any class that implements ApiKeyResource. When you call setApiKey(String) on an APIKeyResource, it will override the default key at the global level (the key returned by ArcGISRuntimeEnvironment.getApiKey(), in other words), enabling more granular usage telemetry and management for ArcGIS Online resources used by your app.

      Classes that expose an API key property by implementing APIKeyResource include:

      Specified by:
      getApiKey in interface ApiKeyResource
      Returns:
      the API key to access API key enabled services and resources in ArcGIS Online
      See Also:
    • setApiKey

      public void setApiKey(String apiKey)
      Description copied from interface: ApiKeyResource
      Sets the API key to access API key enabled services and resources in ArcGIS Online.

      An API key is a unique key used to authorize access to specific services and resources in ArcGIS Online. It is also used to monitor access to those services. An API key is created and managed in the ArcGIS developer dashboard and is tied to a specific ArcGIS account.

      In addition to setting an API key at a global level for your application using ArcGISRuntimeEnvironment.setApiKey(String), you can call setApiKey(String) on any class that implements ApiKeyResource. When you call setApiKey(String) on an APIKeyResource, it will override the default key at the global level (the key returned by ArcGISRuntimeEnvironment.getApiKey(), in other words), enabling more granular usage telemetry and management for ArcGIS Online resources used by your app.

      Classes that expose an API key property by implementing APIKeyResource include:

      Specified by:
      setApiKey in interface ApiKeyResource
      Parameters:
      apiKey - the API key to access API key enabled services and resources in ArcGIS Online
      See Also:
    • getLoadStatus

      public LoadStatus getLoadStatus()
      Gets the value of the property loadStatus.
      Specified by:
      getLoadStatus in interface Loadable
      Property description:
      Returns:
      the LoadStatus of the loadable resource
    • getLoadError

      public ArcGISRuntimeException getLoadError()
      Gets the value of the property loadError.
      Specified by:
      getLoadError in interface Loadable
      Property description:
      Returns:
      the most recent error that was encountered when the loadable resource transitioned to the LoadStatus.FAILED_TO_LOAD state.
    • cancelLoad

      public void cancelLoad()
      Description copied from interface: Loadable
      Cancels loading metadata for the object.

      Cancels loading the metadata if the object is loading, and always invokes the done loading listener.

      A load operation that is in progress (LoadStatus.LOADING state) can be cancelled by calling this method and the resource will transition from LoadStatus.LOADING to LoadStatus.FAILED_TO_LOAD state. If the load operation was successfully cancelled, a CancellationException will be returned from Loadable.getLoadError().

      Cancellation should be used carefully because all enqueued done loading listeners for that resource instance will get invoked with an error stating that the operation was cancelled. Thus, one component in the application can cancel the load operation initiated by other components.

      This method does nothing if the resource is not in LoadStatus.LOADING state.

      Specified by:
      cancelLoad in interface Loadable
    • loadAsync

      public void loadAsync()
      Description copied from interface: Loadable
      Loads the metadata of the loadable resource asynchronously.

      The load status changes from LoadStatus.NOT_LOADED to LoadStatus.LOADING. A listener can be added via Loadable.addDoneLoadingListener(java.lang.Runnable) that is invoked upon completion of the asynchronous load operation.

      If the load operation completes successfully, the load status will be LoadStatus.LOADED, which means the resource has loaded its metadata.

      If the load operation failed, the load status will be LoadStatus.FAILED_TO_LOAD and the error can be retrieved by calling Loadable.getLoadError().

      This method can be called concurrently and repeatedly, but only one attempt is ever made to perform the load operation. If a load operation is already in progress (LoadStatus.LOADING state) when loadAsync is called, it simply piggy-backs on the outstanding operation and the done loading listener added to the loadable resource is enqueued to be invoked when that operation completes. If the operation has already completed (LoadStatus.LOADED or LoadStatus.FAILED_TO_LOAD state) when loadAsync is called, the done loading listener is immediately invoked when added to the loadable resource.

      If a loadable resource has failed to load, calling loadAsync on it subsequently will not change its state. The done loading listener will be invoked immediately when added to the loadable resource. In order to retry loading the resource, Loadable.retryLoadAsync() needs to be used.

      A load operation that is in progress (LoadStatus.LOADING state) can be cancelled by calling Loadable.cancelLoad().

      Specified by:
      loadAsync in interface Loadable
    • retryLoadAsync

      public void retryLoadAsync()
      Description copied from interface: Loadable
      Loads or retries loading metadata for the object asynchronously.

      Will retry loading the metadata if the object's load status is LoadStatus.FAILED_TO_LOAD. Will load the object if it is not loaded. Will not retry to load the object if the object is loaded.

      For more details on the load process see Loadable.loadAsync().

      Specified by:
      retryLoadAsync in interface Loadable
    • addDoneLoadingListener

      public void addDoneLoadingListener(Runnable listener)
      Description copied from interface: Loadable
      Adds a listener to the loadable resource that is invoked when loading has completed.

      The listener may be added at any point, whether the loadable resource has already completed loading or not.

      • For resources that are not loaded when the listener is added (LoadStatus is NOT_LOADED or LOADING): When the resource completes loading, the listener will be invoked on the UI thread if it is added from the UI thread, otherwise it is not guaranteed on which thread the listener is invoked.
      • For resources that are already loaded when the listener is added (LoadStatus is LOADED or FAILED_TO_LOAD): The listener will be called immediately, on the current thread.

      Alternatively, to be notified when there is any change in the load status, add a listener to the Loadable.loadStatusProperty() instead.

      Specified by:
      addDoneLoadingListener in interface Loadable
      Parameters:
      listener - a Runnable that is invoked upon completion of the load operation
    • removeDoneLoadingListener

      public boolean removeDoneLoadingListener(Runnable listener)
      Description copied from interface: Loadable
      Removes a done loading listener from the loadable resource.
      Specified by:
      removeDoneLoadingListener in interface Loadable
      Parameters:
      listener - the listener to be removed
      Returns:
      true if the listener was removed, otherwise false
    • addLoadStatusChangedListener

      public void addLoadStatusChangedListener(LoadStatusChangedListener listener)
      Description copied from interface: Loadable
      Adds a LoadStatusChangedListener to the loadable resource that is invoked whenever the load status changes.

      Adding this listener on the UI thread will cause it to be invoked on the UI thread, otherwise it is not guaranteed on which thread the listener is invoked.

      The listener will not be called if added to a loadable resource that has already completed loading. To be notified when a loadable resource has completed loading, including if the resource is already loaded when the listener is added, use the Loadable.addDoneLoadingListener(Runnable) method.

      Specified by:
      addLoadStatusChangedListener in interface Loadable
      Parameters:
      listener - the LoadStatusChangedListener to be added
    • removeLoadStatusChangedListener

      public boolean removeLoadStatusChangedListener(LoadStatusChangedListener listener)
      Description copied from interface: Loadable
      Removes a LoadStatusChangedListener from the loadable resource.
      Specified by:
      removeLoadStatusChangedListener in interface Loadable
      Parameters:
      listener - the LoadStatusChangedListener to be removed
      Returns:
      true if the listener was removed, otherwise false
    • loadStatusProperty

      public ReadOnlyObjectProperty<LoadStatus> loadStatusProperty()
      Description copied from interface: Loadable
      The load status.
      Specified by:
      loadStatusProperty in interface Loadable
      See Also:
    • loadErrorProperty

      public ReadOnlyObjectProperty<ArcGISRuntimeException> loadErrorProperty()
      Description copied from interface: Loadable
      The load error.
      Specified by:
      loadErrorProperty in interface Loadable
      See Also: