Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
geocodingmanagerengine_esri.cpp
Go to the documentation of this file.
1// Copyright (C) 2013-2018 Esri <contracts@esri.com>
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
5#include "geocodereply_esri.h"
6
7#include <QVariantMap>
8#include <QUrl>
9#include <QUrlQuery>
10#include <QLocale>
11#include <QNetworkAccessManager>
12#include <QNetworkRequest>
13#include <QGeoCoordinate>
14#include <QGeoAddress>
15#include <QGeoShape>
16#include <QGeoRectangle>
17
19
20// https://developers.arcgis.com/rest/geocode/api-reference/geocoding-find-address-candidates.htm
21// https://developers.arcgis.com/rest/geocode/api-reference/geocoding-reverse-geocode.htm
22
23static const QString kPrefixEsri(QStringLiteral("esri."));
25
26static const QString kUrlGeocode(QStringLiteral("https://geocode.arcgis.com/arcgis/rest/services/"
27 "World/GeocodeServer/findAddressCandidates"));
29 "https://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer/reverseGeocode"));
30
32{
33 return address.street() + QStringLiteral(", ")
34 + address.district() + QStringLiteral(", ")
35 + address.city() + QStringLiteral(", ")
36 + address.state() + QStringLiteral(", ")
37 + address.country();
38}
39
41{
42 return QString::number(rect.topLeft().longitude()) + QLatin1Char(',')
43 + QString::number(rect.topLeft().latitude()) + QLatin1Char(',')
44 + QString::number(rect.bottomRight().longitude()) + QLatin1Char(',')
45 + QString::number(rect.bottomRight().latitude());
46}
47
50 QString *errorString)
51: QGeoCodingManagerEngine(parameters), m_networkManager(new QNetworkAccessManager(this))
52{
53 if (parameters.contains(kParamUserAgent))
54 m_userAgent = parameters.value(kParamUserAgent).toString().toLatin1();
55 else
56 m_userAgent = QByteArrayLiteral("Qt Location based application");
57
59 errorString->clear();
60}
61
65
67 const QGeoShape &bounds)
68{
69 return geocode(addressToQuery(address), 1, -1, bounds);
70}
71
73 const QGeoShape &bounds)
74{
76
79
81
84 query.addQueryItem(QStringLiteral("f"), QStringLiteral("json"));
85 query.addQueryItem(QStringLiteral("outFields"), "*");
86
87 if (bounds.type() != QGeoShape::UnknownType)
88 query.addQueryItem(QStringLiteral("searchExtent"), boundingBoxToLtrb(bounds.boundingGeoRectangle()));
89
90 if (limit != -1)
91 query.addQueryItem(QStringLiteral("maxLocations"), QString::number(limit));
92
95
96 QNetworkReply *reply = m_networkManager->get(request);
98
100 this, &GeoCodingManagerEngineEsri::replyFinished);
102 this, &GeoCodingManagerEngineEsri::replyError);
103
104 return geocodeReply;
105}
106
108 const QGeoShape &bounds)
109{
110 Q_UNUSED(bounds);
111
114
116
118
120 query.addQueryItem(QStringLiteral("langCode"), locale().name().left(2));
121 query.addQueryItem(QStringLiteral("location"), QString::number(coordinate.longitude()) + QLatin1Char(',')
122 + QString::number(coordinate.latitude()));
123
126
127 QNetworkReply *reply = m_networkManager->get(request);
129 this);
130
131 connect(geocodeReply, &GeoCodeReplyEsri::finished,
132 this, &GeoCodingManagerEngineEsri::replyFinished);
134 this, &GeoCodingManagerEngineEsri::replyError);
135
136 return geocodeReply;
137}
138
139void GeoCodingManagerEngineEsri::replyFinished()
140{
141 QGeoCodeReply *reply = qobject_cast<QGeoCodeReply *>(sender());
142 if (reply)
144}
145
146void GeoCodingManagerEngineEsri::replyError(QGeoCodeReply::Error errorCode,
147 const QString &errorString)
148{
149 QGeoCodeReply *reply = qobject_cast<QGeoCodeReply *>(sender());
150 if (reply)
151 emit errorOccurred(reply, errorCode, errorString);
152}
153
QGeoCodeReply * reverseGeocode(const QGeoCoordinate &coordinate, const QGeoShape &bounds) override
Begins the reverse geocoding of coordinate.
QGeoCodeReply * geocode(const QGeoAddress &address, const QGeoShape &bounds) override
Begins the geocoding of address.
GeoCodingManagerEngineEsri(const QVariantMap &parameters, QGeoServiceProvider::Error *error, QString *errorString)
\inmodule QtPositioning
Definition qgeoaddress.h:18
\inmodule QtLocation
void finished()
This signal is emitted when this reply has finished processing.
void errorOccurred(QGeoCodeReply::Error error, const QString &errorString=QString())
This signal is emitted when an error has been detected in the processing of this reply.
Error
Describes an error which prevented the completion of the operation.
void errorOccurred(QGeoCodeReply *reply, QGeoCodeReply::Error error, const QString &errorString=QString())
void finished(QGeoCodeReply *reply)
QLocale locale() const
Returns the locale used to hint to this geocoding manager about what language to use for the results.
\inmodule QtPositioning
double longitude
This property holds the longitude in decimal degrees.
double latitude
This property holds the latitude in decimal degrees.
\inmodule QtPositioning
Error
Describes an error related to the loading and setup of a service provider plugin.
\inmodule QtPositioning
Definition qgeoshape.h:17
ShapeType type
This property holds the type of this geo shape.
Definition qgeoshape.h:19
Q_INVOKABLE QGeoRectangle boundingGeoRectangle() const
Returns a QGeoRectangle representing the geographical bounding rectangle of the geo shape,...
@ UnknownType
Definition qgeoshape.h:31
T value(const Key &key, const T &defaultValue=T()) const
Definition qmap.h:357
bool contains(const Key &key) const
Definition qmap.h:341
The QNetworkAccessManager class allows the application to send network requests and receive replies.
QNetworkReply * get(const QNetworkRequest &request)
Posts a request to obtain the contents of the target request and returns a new QNetworkReply object o...
The QNetworkReply class contains the data and headers for a request sent with QNetworkAccessManager.
The QNetworkRequest class holds a request to be sent with QNetworkAccessManager.
void setHeader(KnownHeaders header, const QVariant &value)
Sets the value of the known header header to be value, overriding any previously set headers.
void setUrl(const QUrl &url)
Sets the URL this network request is referring to be url.
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
\threadsafe
Definition qobject.cpp:2960
QObject * sender() const
Returns a pointer to the object that sent the signal, if called in a slot activated by a signal; othe...
Definition qobject.cpp:2658
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
QByteArray toLatin1() const &
Definition qstring.h:630
static QString number(int, int base=10)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition qstring.cpp:8084
\inmodule QtCore
Definition qurlquery.h:20
void addQueryItem(const QString &key, const QString &value)
Appends the pair key = value to the end of the query string of the URL.
\inmodule QtCore
Definition qurl.h:94
void setQuery(const QString &query, ParsingMode mode=TolerantMode)
Sets the query string of the URL to query.
Definition qurl.cpp:2550
QString toString() const
Returns the variant as a QString if the variant has a userType() including, but not limited to:
#define this
Definition dialogs.cpp:9
rect
[4]
static QString boundingBoxToLtrb(const QGeoRectangle &rect)
static const QString kParamUserAgent(kPrefixEsri+QStringLiteral("useragent"))
static const QString kUrlReverseGeocode(QStringLiteral("https://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer/reverseGeocode"))
static const QString kUrlGeocode(QStringLiteral("https://geocode.arcgis.com/arcgis/rest/services/" "World/GeocodeServer/findAddressCandidates"))
static QString addressToQuery(const QGeoAddress &address)
static QT_BEGIN_NAMESPACE const QString kPrefixEsri(QStringLiteral("esri."))
Combined button and popup list for selecting options.
#define QByteArrayLiteral(str)
Definition qbytearray.h:52
DBusConnection const char DBusError * error
GLint left
GLenum GLuint GLintptr offset
GLuint name
GLenum query
GLint limit
GLuint GLuint64EXT address
#define QStringLiteral(str)
#define emit
#define Q_UNUSED(x)
QUrl url("example.com")
[constructor-url-reference]
QNetworkRequest request(url)
QNetworkReply * reply
\inmodule QtCore \reentrant
Definition qchar.h:18