- All Implemented Interfaces:
ApiKeyResource
,RemoteResource
,Loadable
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 Summary
TypePropertyDescriptionThe load error.The load status. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addDoneLoadingListener
(Runnable listener) Adds a listener to the loadable resource that is invoked when loading has completed.void
Adds aLoadStatusChangedListener
to the loadable resource that is invoked whenever the load status changes.void
Cancels loading metadata for the object.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.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.geocodeAsync
(String searchText) Executes an asynchronous geocode operation to find location candidates for a given address.geocodeAsync
(String searchText, GeocodeParameters parameters) Executes an asynchronous geocode operation to find location candidates for a given address.geocodeAsync
(Map<String, String> searchValues) Executes an asynchronous geocode operation to find location candidates for a given multi-line address.geocodeAsync
(Map<String, String> searchValues, GeocodeParameters parameters) Executes an asynchronous geocode operation to find location candidates for a given multi-line address.Gets the API key to access API key enabled services and resources in ArcGIS Online.Gets the credential used to authenticate the user with this task.Gets the value of theloadError
property.Gets the value of theloadStatus
property.Gets information about this LocatorTask.Gets the RequestConfiguration object in use by this task.getUri()
Gets the URI of this task.void
Loads the metadata of the loadable resource asynchronously.The load error.The load status.boolean
removeDoneLoadingListener
(Runnable listener) Removes a done loading listener from the loadable resource.boolean
Removes aLoadStatusChangedListener
from the loadable resource.void
Loads or retries loading metadata for the object asynchronously.reverseGeocodeAsync
(Point location) Executes an asynchronous reverse geocode operation to find address candidates for a given location.reverseGeocodeAsync
(Point location, ReverseGeocodeParameters parameters) Executes an asynchronous reverse geocode operation to find address candidates for a given location.void
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.suggestAsync
(String searchText) Executes an asynchronous suggest operation to fetch suggestions for a given search text.suggestAsync
(String searchText, SuggestParameters parameters) Executes an asynchronous suggest operation to fetch suggestions for a given search text.
-
Property Details
-
loadStatus
- Specified by:
loadStatusProperty
in interfaceLoadable
- Returns:
- the
loadStatus
property - See Also:
-
loadError
- Specified by:
loadErrorProperty
in interfaceLoadable
- Returns:
- the
loadError
property - See Also:
-
-
Constructor Details
-
LocatorTask
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
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
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
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
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:
-
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
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
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:
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 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:
IllegalArgumentException
- if searchText is null, or if parameters is null- Since:
- 100.0.0
-
geocodeAsync
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:
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 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:
IllegalArgumentException
- if searchValues is null or empty, or parameters is null- Since:
- 100.0.0
-
geocodeAsync
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:
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 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:
IllegalArgumentException
- if suggestResult or parameters is null- Since:
- 100.0.0
- See Also:
-
reverseGeocodeAsync
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:
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 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:
IllegalArgumentException
- if location or parameters is null- Since:
- 100.0.0
-
suggestAsync
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:
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 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:
IllegalArgumentException
- if searchText is null or empty, or if parameters is null- Since:
- 100.0.0
-
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 long-lived access token that is used to authenticate and monitor requests to ArcGIS location services and private portal items. You can create and manage an API key using your portal when you sign in with an ArcGIS Location Platform account or an ArcGIS Online account with administrator access or a custom role that has the Generate API keys privilege. To learn how to create and manage API keys, go to the Create an API Key tutorial. You must ensure that your API key has the correct privileges to access secure resources.
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 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:
-
setApiKey
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 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:
-
getLoadStatus
Gets the value of theloadStatus
property.- Specified by:
getLoadStatus
in interfaceLoadable
- Property description:
- Returns:
- the value of the
loadStatus
property - See Also:
-
getLoadError
Gets the value of theloadError
property.- Specified by:
getLoadError
in interfaceLoadable
- Property description:
- Returns:
- the value of the
loadError
property - See Also:
-
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
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 interfaceLoadable
- Parameters:
listener
- a Runnable that is invoked upon completion of the load operation
-
removeDoneLoadingListener
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
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
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
-
loadStatusProperty
Description copied from interface:Loadable
The load status.- Specified by:
loadStatusProperty
in interfaceLoadable
- Returns:
- the
loadStatus
property - See Also:
-
loadErrorProperty
Description copied from interface:Loadable
The load error.- Specified by:
loadErrorProperty
in interfaceLoadable
- Returns:
- the
loadError
property - See Also:
-