Class LocatorTask
- java.lang.Object
-
- com.esri.arcgisruntime.tasks.geocode.LocatorTask
-
- All Implemented Interfaces:
ApiKeyResource
,RemoteResource
,Loadable
public final class LocatorTask extends java.lang.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
-
-
Constructor Summary
Constructors Constructor Description LocatorTask(java.lang.String uri)
Constructs an online or offline LocatorTask.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addDoneLoadingListener(java.lang.Runnable listener)
Adds a listener to the loadable resource that is invoked when loading has completed.void
addLoadStatusChangedListener(LoadStatusChangedListener listener)
Adds aLoadStatusChangedListener
to the loadable resource that is invoked whenever the load status changes.void
cancelLoad()
Cancels loading metadata for the object.ListenableFuture<java.util.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.ListenableFuture<java.util.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.ListenableFuture<java.util.List<GeocodeResult>>
geocodeAsync(java.lang.String searchText)
Executes an asynchronous geocode operation to find location candidates for a given address.ListenableFuture<java.util.List<GeocodeResult>>
geocodeAsync(java.lang.String searchText, GeocodeParameters parameters)
Executes an asynchronous geocode operation to find location candidates for a given address.ListenableFuture<java.util.List<GeocodeResult>>
geocodeAsync(java.util.Map<java.lang.String,java.lang.String> searchValues)
Executes an asynchronous geocode operation to find location candidates for a given multi-line address.ListenableFuture<java.util.List<GeocodeResult>>
geocodeAsync(java.util.Map<java.lang.String,java.lang.String> searchValues, GeocodeParameters parameters)
Executes an asynchronous geocode operation to find location candidates for a given multi-line address.java.lang.String
getApiKey()
Gets the API key to access API key enabled services and resources in ArcGIS Online.Credential
getCredential()
Gets the credential used to authenticate the user with this task.ArcGISRuntimeException
getLoadError()
Returns the most recent error that was encountered when the loadable resource transitioned to theLoadStatus.FAILED_TO_LOAD
state, either due to calling theLoadable.loadAsync()
orLoadable.retryLoadAsync()
method.LoadStatus
getLoadStatus()
Returns theLoadStatus
of the loadable resource.LocatorInfo
getLocatorInfo()
Gets information about this LocatorTask.RequestConfiguration
getRequestConfiguration()
Gets the RequestConfiguration object in use by this task.java.lang.String
getUri()
Gets the URI of this task.void
loadAsync()
Loads the metadata of the loadable resource asynchronously.boolean
removeDoneLoadingListener(java.lang.Runnable listener)
Removes a done loading listener from the loadable resource.boolean
removeLoadStatusChangedListener(LoadStatusChangedListener listener)
Removes aLoadStatusChangedListener
from the loadable resource.void
retryLoadAsync()
Loads or retries loading metadata for the object asynchronously.ListenableFuture<java.util.List<GeocodeResult>>
reverseGeocodeAsync(Point location)
Executes an asynchronous reverse geocode operation to find address candidates for a given location.ListenableFuture<java.util.List<GeocodeResult>>
reverseGeocodeAsync(Point location, ReverseGeocodeParameters parameters)
Executes an asynchronous reverse geocode operation to find address candidates for a given location.void
setApiKey(java.lang.String apiKey)
Sets the API key to access API key enabled services and resources in ArcGIS Online.void
setCredential(Credential credential)
Sets the credential used to authenticate the user with this task.void
setRequestConfiguration(RequestConfiguration requestConfiguration)
Sets configuration parameters used for network requests sent using this task.ListenableFuture<java.util.List<SuggestResult>>
suggestAsync(java.lang.String searchText)
Executes an asynchronous suggest operation to fetch suggestions for a given search text.ListenableFuture<java.util.List<SuggestResult>>
suggestAsync(java.lang.String searchText, SuggestParameters parameters)
Executes an asynchronous suggest operation to fetch suggestions for a given search text.
-
-
-
Constructor Detail
-
LocatorTask
public LocatorTask(java.lang.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:
java.lang.IllegalArgumentException
- if uri is null or empty- Since:
- 100.0.0
-
-
Method Detail
-
setCredential
public void setCredential(Credential credential)
Sets the credential used to authenticate the user with this task.- Specified by:
setCredential
in interfaceRemoteResource
- 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 interfaceRemoteResource
- 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 interfaceRemoteResource
- 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 interfaceRemoteResource
- Returns:
- the RequestConfiguration object, or null if none has been set
- Since:
- 100.0.0
- See Also:
RequestConfiguration
-
getUri
public java.lang.String getUri()
Gets the URI of this task. This is the URI used to instantiate the object.- Specified by:
getUri
in interfaceRemoteResource
- 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<java.util.List<GeocodeResult>> geocodeAsync(java.lang.String searchText)
Executes an asynchronous geocode operation to find location candidates for a given address. The result is an unmodifiable List ofGeocodeResult
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:
java.lang.IllegalArgumentException
- if searchText is null or empty- Since:
- 100.0.0
-
geocodeAsync
public ListenableFuture<java.util.List<GeocodeResult>> geocodeAsync(java.lang.String searchText, GeocodeParameters parameters)
Executes an asynchronous geocode operation to find location candidates for a given address. The result is an unmodifiable List ofGeocodeResult
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:
java.lang.IllegalArgumentException
- if searchText is null, or if parameters is null- Since:
- 100.0.0
-
geocodeAsync
public ListenableFuture<java.util.List<GeocodeResult>> geocodeAsync(java.util.Map<java.lang.String,java.lang.String> searchValues)
Executes an asynchronous geocode operation to find location candidates for a given multi-line address. The result is an unmodifiable List ofGeocodeResult
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:
java.lang.IllegalArgumentException
- if searchValues is null or empty- Since:
- 100.0.0
-
geocodeAsync
public ListenableFuture<java.util.List<GeocodeResult>> geocodeAsync(java.util.Map<java.lang.String,java.lang.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 ofGeocodeResult
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 addressparameters
- 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:
java.lang.IllegalArgumentException
- if searchValues is null or empty, or parameters is null- Since:
- 100.0.0
-
geocodeAsync
public ListenableFuture<java.util.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 ofGeocodeResult
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:
java.lang.IllegalArgumentException
- if suggestResult is null- Since:
- 100.0.0
- See Also:
suggestAsync(String)
,suggestAsync(String, SuggestParameters)
-
geocodeAsync
public ListenableFuture<java.util.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 ofGeocodeResult
objects.- Parameters:
suggestResult
- a SuggestResult object returned by a call to one of the suggestAsync methodsparameters
- 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:
java.lang.IllegalArgumentException
- if suggestResult or parameters is null- Since:
- 100.0.0
- See Also:
suggestAsync(String)
,suggestAsync(String, SuggestParameters)
-
reverseGeocodeAsync
public ListenableFuture<java.util.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 ofGeocodeResult
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:
java.lang.IllegalArgumentException
- if location is null- Since:
- 100.0.0
-
reverseGeocodeAsync
public ListenableFuture<java.util.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 ofGeocodeResult
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 addressparameters
- 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:
java.lang.IllegalArgumentException
- if location or parameters is null- Since:
- 100.0.0
-
suggestAsync
public ListenableFuture<java.util.List<SuggestResult>> suggestAsync(java.lang.String searchText)
Executes an asynchronous suggest operation to fetch suggestions for a given search text. The result is an unmodifiable List ofSuggestResult
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, useSuggestParameters.setPreferredSearchLocation(Point)
orSuggestParameters.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:
java.lang.IllegalArgumentException
- if searchText is null or empty- Since:
- 100.0.0
-
suggestAsync
public ListenableFuture<java.util.List<SuggestResult>> suggestAsync(java.lang.String searchText, SuggestParameters parameters)
Executes an asynchronous suggest operation to fetch suggestions for a given search text. The result is an unmodifiable List ofSuggestResult
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, useSuggestParameters.setPreferredSearchLocation(Point)
orSuggestParameters.setSearchArea(Geometry)
. UsingSuggestParameters.setPreferredSearchLocation(Point)
} is similar to how ArcGIS Pro limits the suggestions returned.- Parameters:
searchText
- a text string entered by a userparameters
- 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:
java.lang.IllegalArgumentException
- if searchText is null or empty, or if parameters is null- Since:
- 100.0.0
-
getApiKey
public java.lang.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 callApiKeyResource.setApiKey(String)
on any ArcGIS Runtime class that implementsApiKeyResource
. When you callsetApiKey(String)
on anAPIKeyResource
, it will override the default key at the global level (the key returned byArcGISRuntimeEnvironment.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 interfaceApiKeyResource
- Returns:
- the API key to access API key enabled services and resources in ArcGIS Online
- See Also:
ApiKeyResource.setApiKey(String)
-
setApiKey
public void setApiKey(java.lang.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 callsetApiKey(String)
on any ArcGIS Runtime class that implementsApiKeyResource
. When you callsetApiKey(String)
on anAPIKeyResource
, it will override the default key at the global level (the key returned byArcGISRuntimeEnvironment.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 interfaceApiKeyResource
- Parameters:
apiKey
- the API key to access API key enabled services and resources in ArcGIS Online- See Also:
ApiKeyResource.getApiKey()
-
getLoadStatus
public LoadStatus getLoadStatus()
Description copied from interface:Loadable
Returns theLoadStatus
of the loadable resource.- Specified by:
getLoadStatus
in interfaceLoadable
- Returns:
- the LoadStatus of the loadable resource
-
getLoadError
public ArcGISRuntimeException getLoadError()
Description copied from interface:Loadable
Returns the most recent error that was encountered when the loadable resource transitioned to theLoadStatus.FAILED_TO_LOAD
state, either due to calling theLoadable.loadAsync()
orLoadable.retryLoadAsync()
method.If the resource subsequently transitions to
LoadStatus.LOADED
(for example, if a call toretryLoadAsync
completes successfully) the error is cleared out.- Specified by:
getLoadError
in interfaceLoadable
- 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 fromLoadStatus.LOADING
toLoadStatus.FAILED_TO_LOAD
state. If the load operation was successfully cancelled, a CancellationException will be returned fromLoadable.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 interfaceLoadable
-
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
toLoadStatus.LOADING
. A listener can be added viaLoadable.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 callingLoadable.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) whenloadAsync
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
orLoadStatus.FAILED_TO_LOAD
state) whenloadAsync
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 callingLoadable.cancelLoad()
.
-
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 interfaceLoadable
-
addDoneLoadingListener
public void addDoneLoadingListener(java.lang.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, use the
Loadable.addLoadStatusChangedListener(LoadStatusChangedListener)
method instead.- Specified by:
addDoneLoadingListener
in interfaceLoadable
- Parameters:
listener
- a Runnable that is invoked upon completion of the load operation
-
removeDoneLoadingListener
public boolean removeDoneLoadingListener(java.lang.Runnable listener)
Description copied from interface:Loadable
Removes a done loading listener from the loadable resource.- Specified by:
removeDoneLoadingListener
in interfaceLoadable
- 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 aLoadStatusChangedListener
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 interfaceLoadable
- Parameters:
listener
- theLoadStatusChangedListener
to be added
-
removeLoadStatusChangedListener
public boolean removeLoadStatusChangedListener(LoadStatusChangedListener listener)
Description copied from interface:Loadable
Removes aLoadStatusChangedListener
from the loadable resource.- Specified by:
removeLoadStatusChangedListener
in interfaceLoadable
- Parameters:
listener
- theLoadStatusChangedListener
to be removed- Returns:
- true if the listener was removed, otherwise false
-
-