11#include <QNetworkAccessManager>
12#include <QNetworkRequest>
13#include <QGeoCoordinate>
16#include <QGeoRectangle>
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"));
33 return address.street() + QStringLiteral(
", ")
34 + address.district() + QStringLiteral(
", ")
35 + address.city() + QStringLiteral(
", ")
36 + address.state() + QStringLiteral(
", ")
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());
49 QGeoServiceProvider::Error *error,
51: QGeoCodingManagerEngine(parameters), m_networkManager(
new QNetworkAccessManager(
this))
53 if (parameters.contains(kParamUserAgent))
54 m_userAgent = parameters.value(kParamUserAgent).toString().toLatin1();
56 m_userAgent = QByteArrayLiteral(
"Qt Location based application");
58 *error = QGeoServiceProvider::NoError;
67 const QGeoShape &bounds)
69 return geocode(addressToQuery(address), 1, -1, bounds);
73 const QGeoShape &bounds)
77 QNetworkRequest request;
78 request.setHeader(QNetworkRequest::UserAgentHeader, m_userAgent);
83 query.addQueryItem(QStringLiteral(
"singleLine"), address);
84 query.addQueryItem(QStringLiteral(
"f"), QStringLiteral(
"json"));
85 query.addQueryItem(QStringLiteral(
"outFields"),
"*");
87 if (bounds.type() != QGeoShape::UnknownType)
88 query.addQueryItem(QStringLiteral(
"searchExtent"), boundingBoxToLtrb(bounds.boundingGeoRectangle()));
91 query.addQueryItem(QStringLiteral(
"maxLocations"), QString::number(limit));
96 QNetworkReply *reply = m_networkManager->get(request);
97 GeoCodeReplyEsri *geocodeReply =
new GeoCodeReplyEsri(reply, GeoCodeReplyEsri::Geocode,
this);
99 connect(geocodeReply, &GeoCodeReplyEsri::finished,
100 this, &GeoCodingManagerEngineEsri::replyFinished);
101 connect(geocodeReply, &GeoCodeReplyEsri::errorOccurred,
102 this, &GeoCodingManagerEngineEsri::replyError);
108 const QGeoShape &bounds)
112 QNetworkRequest request;
113 request.setHeader(QNetworkRequest::UserAgentHeader, m_userAgent);
119 query.addQueryItem(QStringLiteral(
"f"), QStringLiteral(
"json"));
120 query.addQueryItem(QStringLiteral(
"langCode"), locale().name().left(2));
121 query.addQueryItem(QStringLiteral(
"location"), QString::number(coordinate.longitude()) + QLatin1Char(
',')
122 + QString::number(coordinate.latitude()));
127 QNetworkReply *reply = m_networkManager->get(request);
128 GeoCodeReplyEsri *geocodeReply =
new GeoCodeReplyEsri(reply, GeoCodeReplyEsri::ReverseGeocode,
131 connect(geocodeReply, &GeoCodeReplyEsri::finished,
132 this, &GeoCodingManagerEngineEsri::replyFinished);
133 connect(geocodeReply, &GeoCodeReplyEsri::errorOccurred,
134 this, &GeoCodingManagerEngineEsri::replyError);
141 QGeoCodeReply *reply = qobject_cast<QGeoCodeReply *>(sender());
143 emit finished(reply);
147 const QString &errorString)
149 QGeoCodeReply *reply = qobject_cast<QGeoCodeReply *>(sender());
151 emit errorOccurred(reply, errorCode, errorString);
QGeoCodeReply * geocode(const QString &address, int limit, int offset, const QGeoShape &bounds) override
Begins geocoding for a location matching address.
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.
virtual ~GeoCodingManagerEngineEsri()
static const QString kUrlGeocode(QStringLiteral("https://geocode.arcgis.com/arcgis/rest/services/" "World/GeocodeServer/findAddressCandidates"))
static QString boundingBoxToLtrb(const QGeoRectangle &rect)
static const QString kParamUserAgent(kPrefixEsri+QStringLiteral("useragent"))
static QString addressToQuery(const QGeoAddress &address)
static const QString kUrlReverseGeocode(QStringLiteral("https://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer/reverseGeocode"))
static QT_BEGIN_NAMESPACE const QString kPrefixEsri(QStringLiteral("esri."))
Combined button and popup list for selecting options.