Skip To Content ArcGIS for Developers Sign In Dashboard

LocatorTask Class

(Esri::ArcGISRuntime::LocatorTask)

A task for Geocoding and Reverse Geocoding that supports both online and offline capabilities. More...

Header: #include <LocatorTask>
Since: Esri::ArcGISRuntime 100.0
Inherits: Object, Loadable, and RemoteResource

Public Functions

LocatorTask(const QUrl &url, QObject *parent = nullptr)
LocatorTask(const QUrl &url, Credential *credential, QObject *parent = nullptr)
~LocatorTask()
TaskWatcher geocode(const QString &searchText)
TaskWatcher geocodeWithParameters(const QString &searchText, const GeocodeParameters &parameters)
TaskWatcher geocodeWithSearchValues(const QMap<QString, QString> &searchValues)
TaskWatcher geocodeWithSearchValuesAndParameters(const QMap<QString, QString> &searchValues, const GeocodeParameters &parameters)
TaskWatcher geocodeWithSuggestResult(const SuggestResult &suggestResult)
TaskWatcher geocodeWithSuggestResultAndParameters(const SuggestResult &suggestResult, const GeocodeParameters &parameters)
LocatorInfo locatorInfo() const
TaskWatcher reverseGeocode(const Point &location)
TaskWatcher reverseGeocodeWithParameters(const Point &location, const ReverseGeocodeParameters &parameters)
SuggestListModel *suggestions() const

Reimplemented Public Functions

virtual void cancelLoad()
virtual Credential *credential() const
virtual void load()
virtual Error loadError() const
virtual LoadStatus loadStatus() const
virtual RequestConfiguration requestConfiguration() const
virtual void retryLoad()
virtual void setRequestConfiguration(const RequestConfiguration &requestConfiguration)
virtual QUrl url() const

Signals

void doneLoading(Esri::ArcGISRuntime::Error loadError)
void geocodeCompleted(QUuid taskId, const QList<Esri::ArcGISRuntime::GeocodeResult> &geocodeResults)
void loadStatusChanged(Esri::ArcGISRuntime::LoadStatus loadStatus)

Additional Inherited Members

  • 1 property inherited from QObject
  • 1 public slot inherited from QObject
  • 1 public variable inherited from QObject
  • 10 static public members inherited from QObject
  • 9 protected functions inherited from QObject
  • 2 protected variables inherited from QObject

Detailed Description

A task for Geocoding and Reverse Geocoding that supports both online and offline capabilities.

Geocoding takes an address or place name, and converts it into real-world coordinates. For example, "380 New York St, Redlands, CA", "Yosemite National Park", or "Utility Pole 527" all represent a location on the Earth, but must first be geocoded to convert their written description or address to a set of real-world coordinates that can be placed on a map. Reverse Geocoding is similar to Geocoding, only instead of finding the coordinates associated with a particular address or place name, it finds the closest address or place name from given map coordinates. For example, a user could click on a map of New York City, and get the address of the coordinates from that click.

An Address Locator is required to geocode with a LocatorTask. If working in an online connected scenario, the locator can be published to ArcGIS Server, as an online geocoding service. Esri also provides ready-to-use services, such as the World Geocoding Service, which requires authentication with an ArcGIS organizational account. If working in a disconnected scenario, the locator can be exported as a Runtime-enabled address locator from either ArcMap or ArcGIS Pro. If you are using ArcMap, run the Create Runtime Content geoprocessing tool, and reference a map document that contains the address locator you want to export. This will output a folder containing several files, including a *.loc, *.lox, *.loc.xml, and *.locb. Create the locator task by passing a URL to the location of the *.loc file. If you are using ArcGIS Pro, run the Create Mobile Map Package geoprocessing tool, and select the map and locator that you wish to export. This will output a mobile map package (*.mmpk), which will contain the LocatorTask.

A LocatorTask is executed asynchronously. A successful execution returns a list of GeocodeResult with details about the matched records. The LocatorTask also supports Suggestions, which allow the developer to show auto-generated suggestions from the locator, based on what the user has typed in a search box.

// create the locator task
m_locatorTask = new LocatorTask(QUrl("http://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer"), this);

// connect to the loadStatusChanged signal
connect(m_locatorTask, &LocatorTask::loadStatusChanged, this, [](LoadStatus loadStatus)
{
  if (loadStatus == LoadStatus::Loaded)
  {
    qDebug() << "Locator is ready to use";
  }
  else if (loadStatus == LoadStatus::FailedToLoad)
  {
    qDebug() << "Locator failed to load";
  }
});

// load the locator task
m_locatorTask->load();

See also Loadable and MobileMapPackage.

Member Function Documentation

LocatorTask::LocatorTask(const QUrl &url, QObject *parent = nullptr)

Constructor that takes a url to a local locator or online geocode service, with an optional parent.

LocatorTask::LocatorTask(const QUrl &url, Credential *credential, QObject *parent = nullptr)

Constructor that takes a url to a secured online geocode service and a credential, with an optional parent.

LocatorTask::~LocatorTask()

Destructor.

[virtual] void LocatorTask::cancelLoad()

Reimplemented from Loadable::cancelLoad().

See Loadable.

[virtual] Credential *LocatorTask::credential() const

Reimplemented from RemoteResource::credential().

Returns the security credential used to access the geocoding service.

Note: Only applicable if using an online service that is secured.

[signal] void LocatorTask::doneLoading(Esri::ArcGISRuntime::Error loadError)

Signal emitted when this object is done loading.

  • loadError - The Error object.

Note: If there is a load error it will also be emitted on the errorOccurred signal.

See also Loadable and Object.

TaskWatcher LocatorTask::geocode(const QString &searchText)

Geocodes an address with the given searchText.

Use the LocatorTask::locatorInfo to determine the types of search text supported by the locator. Potential searches could be an address (380 New York St.), a point of interest (Starbucks), or an intersection (Redlands Blvd and Tennessee St).

The geocodeCompleted signal emits when the operation is complete, giving access to the list of GeocodeResult.

[signal] void LocatorTask::geocodeCompleted(QUuid taskId, const QList<Esri::ArcGISRuntime::GeocodeResult> &geocodeResults)

Signal emitted after any of the geocode asynchronous methods complete.

  • taskId - The task ID of the asynchronous task.
  • geocodeResults - The generated list of geocode results.

TaskWatcher LocatorTask::geocodeWithParameters(const QString &searchText, const GeocodeParameters &parameters)

Geocodes an address with the given searchText and parameters.

Use the LocatorTask::locatorInfo to determine the types of search text supported by the locator. Potential searches could be an address (380 New York St.), a point of interest (Starbucks), or an intersection (Redlands Blvd and Tennessee St). The parameters allow you to set preferences, such as maximum number of results or search location.

The geocodeCompleted signal emits when the operation is complete, giving access to the list of GeocodeResult.

TaskWatcher LocatorTask::geocodeWithSearchValues(const QMap<QString, QString> &searchValues)

Geocodes an address with the given searchValues.

Use the LocatorTask::locatorInfo to determine the types of search text supported by the locator. SearchValues are key-value pairs, where the key is an attribute name, and the value is the value you are searching for in that field. Check LocatorInfo::searchAttributes for the search attributes available in the locator.

The geocodeCompleted signal emits when the operation is complete, giving access to the list of GeocodeResult.

TaskWatcher LocatorTask::geocodeWithSearchValuesAndParameters(const QMap<QString, QString> &searchValues, const GeocodeParameters &parameters)

Geocodes an address with the given searchValues and parameters.

Use the LocatorTask::locatorInfo to determine the types of search text supported by the locator. SearchValues are key-value pairs, where the key is an attribute name, and the value is the value you are searching for in that field. Check LocatorInfo::searchAttributes for the search attributes available in the locator. The parameters allow you to set preferences, such as maximum number of results or search location.

The geocodeCompleted signal emits when the operation is complete, giving access to the list of GeocodeResult.

TaskWatcher LocatorTask::geocodeWithSuggestResult(const SuggestResult &suggestResult)

Geocodes an address with the given suggestResult.

Use the LocatorTask::locatorInfo to determine if suggestions are supported by the locator. If so, suggestions can be used to provide a nice user experience where potential results are shown to the user while typing. A SuggestResult can be selected by a user, and directly passed into this function to perform a geocode.

The geocodeCompleted signal emits when the operation is complete, giving access to the list of GeocodeResult.

TaskWatcher LocatorTask::geocodeWithSuggestResultAndParameters(const SuggestResult &suggestResult, const GeocodeParameters &parameters)

Geocodes an address with the given suggestResult and parameters.

Use the LocatorTask::locatorInfo to determine if suggestions are supported by the locator. If so, suggestions can be used to provide a nice user experience where potential results are shown to the user while typing. A SuggestResult can be selected by a user, and directly passed into this function to perform a geocode. The parameters allow you to set preferences, such as maximum number of results or search location.

The geocodeCompleted signal emits when the operation is complete, giving access to the list of GeocodeResult.

[virtual] void LocatorTask::load()

Reimplemented from Loadable::load().

See Loadable.

[virtual] Error LocatorTask::loadError() const

Reimplemented from Loadable::loadError().

See Loadable.

[virtual] LoadStatus LocatorTask::loadStatus() const

Reimplemented from Loadable::loadStatus().

See Loadable.

[signal] void LocatorTask::loadStatusChanged(Esri::ArcGISRuntime::LoadStatus loadStatus)

Signal emitted when the load status changes for this object.

See also Loadable.

LocatorInfo LocatorTask::locatorInfo() const

Returns information about the locator used in this task.

[virtual] RequestConfiguration LocatorTask::requestConfiguration() const

Reimplemented from RemoteResource::requestConfiguration().

Returns the RequestConfiguration in use by this task.

This function was introduced in Esri::ArcGISRuntime 100.1.

See also setRequestConfiguration().

[virtual] void LocatorTask::retryLoad()

Reimplemented from Loadable::retryLoad().

See Loadable.

TaskWatcher LocatorTask::reverseGeocode(const Point &location)

Reverse Geocodes an address with the given location.

A common use case for this function is to create a Point from a mouse click on a map or from some other source, and use this function to obtain the nearest address to the location.

The geocodeCompleted signal emits when the operation is complete, giving access to the list of GeocodeResult.

Note: The input point can be in any spatial reference. If the provided point does not have a spatial reference set on it, the locator task will assume it is in the spatial reference of the locator.

TaskWatcher LocatorTask::reverseGeocodeWithParameters(const Point &location, const ReverseGeocodeParameters &parameters)

Reverse Geocodes an address with the given location and parameters.

A common use case for this function is to create a Point from a mouse click on a map or from some other source, and use this function to obtain the nearest address to the location. The parameters allow you to set preferences, such as maximum number of results or maximum search distance.

The geocodeCompleted signal emits when the operation is complete, giving access to the list of GeocodeResult.

Note: The input point can be in any spatial reference. If the provided point does not have a spatial reference set on it, the locator task will assume it is in the spatial reference of the locator.

[virtual] void LocatorTask::setRequestConfiguration(const RequestConfiguration &requestConfiguration)

Reimplemented from RemoteResource::setRequestConfiguration().

Sets configuration parameters used for network requests sent by this task to requestConfiguration.

This function was introduced in Esri::ArcGISRuntime 100.1.

See also requestConfiguration().

SuggestListModel *LocatorTask::suggestions() const

Returns the SuggestListModel for this LocatorTask.

Use the LocatorTask::locatorInfo to determine if suggestions are supported by the locator. If so, suggestions can be used to provide a nice user experience where potential results are shown to the user while typing. If suggestions are supported by the LocatorTask, suggestions can be automatically generated by calling SuggestListModel::setSearchText. This list model can then be applied to a view to show suggested addresses or place names. See the SuggestListModel API documentation for further details.

[virtual] QUrl LocatorTask::url() const

Reimplemented from RemoteResource::url().

Returns the URL specified on the constructor.


Feedback on this topic?