summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruno de Oliveira Abinader <bruno@mapbox.com>2017-11-16 15:27:29 +0200
committerPaolo Angelelli <paolo.angelelli@qt.io>2017-11-29 23:02:22 +0000
commite5fab0a22988ed98657a4954b0104cc25213effc (patch)
tree6734bfbf7224e7ea4c0ba5196c751790fc8d3518
parentdd497406d343a60b3173eb6749063abb698c5f1b (diff)
downloadqtlocation-e5fab0a22988ed98657a4954b0104cc25213effc.tar.gz
Implement QGeoCodingManagerEngineMapbox
Implements QtLocation's Geocoding functionality, providing forward and reverse geocoding based on Mapbox web services APIs [1]. New 'mapbox' plugin features: - "OnlineGeocodingFeature" - "ReverseGeocodingFeature" - "LocalizedGeocodingFeature" [1] https://www.mapbox.com/api-documentation Change-Id: Icaaf06373bd5c2b5abc5aed3cea46364664cae8f Reviewed-by: Paolo Angelelli <paolo.angelelli@qt.io>
-rw-r--r--src/plugins/geoservices/mapbox/mapbox.pro4
-rw-r--r--src/plugins/geoservices/mapbox/mapbox_plugin.json5
-rw-r--r--src/plugins/geoservices/mapbox/qgeocodereplymapbox.cpp106
-rw-r--r--src/plugins/geoservices/mapbox/qgeocodereplymapbox.h63
-rw-r--r--src/plugins/geoservices/mapbox/qgeocodingmanagerenginemapbox.cpp205
-rw-r--r--src/plugins/geoservices/mapbox/qgeocodingmanagerenginemapbox.h83
-rw-r--r--src/plugins/geoservices/mapbox/qgeoserviceproviderpluginmapbox.cpp25
-rw-r--r--tests/auto/qgeoserviceprovider/tst_qgeoserviceprovider.cpp4
8 files changed, 483 insertions, 12 deletions
diff --git a/src/plugins/geoservices/mapbox/mapbox.pro b/src/plugins/geoservices/mapbox/mapbox.pro
index e017b798..25a12795 100644
--- a/src/plugins/geoservices/mapbox/mapbox.pro
+++ b/src/plugins/geoservices/mapbox/mapbox.pro
@@ -14,6 +14,8 @@ HEADERS += \
qplacemanagerenginemapbox.h \
qplacesearchsuggestionreplymapbox.h \
qplacesearchreplymapbox.h \
+ qgeocodingmanagerenginemapbox.h \
+ qgeocodereplymapbox.h \
qmapboxcommon.h
SOURCES += \
@@ -28,6 +30,8 @@ SOURCES += \
qplacemanagerenginemapbox.cpp \
qplacesearchsuggestionreplymapbox.cpp \
qplacesearchreplymapbox.cpp \
+ qgeocodingmanagerenginemapbox.cpp \
+ qgeocodereplymapbox.cpp \
qmapboxcommon.cpp
RESOURCES += mapbox.qrc
diff --git a/src/plugins/geoservices/mapbox/mapbox_plugin.json b/src/plugins/geoservices/mapbox/mapbox_plugin.json
index a8affe4c..ed594add 100644
--- a/src/plugins/geoservices/mapbox/mapbox_plugin.json
+++ b/src/plugins/geoservices/mapbox/mapbox_plugin.json
@@ -9,6 +9,9 @@
"OnlinePlacesFeature",
"PlaceRecommendationsFeature",
"SearchSuggestionsFeature",
- "LocalizedPlacesFeature"
+ "LocalizedPlacesFeature",
+ "OnlineGeocodingFeature",
+ "ReverseGeocodingFeature",
+ "LocalizedGeocodingFeature"
]
}
diff --git a/src/plugins/geoservices/mapbox/qgeocodereplymapbox.cpp b/src/plugins/geoservices/mapbox/qgeocodereplymapbox.cpp
new file mode 100644
index 00000000..db7a35c4
--- /dev/null
+++ b/src/plugins/geoservices/mapbox/qgeocodereplymapbox.cpp
@@ -0,0 +1,106 @@
+/****************************************************************************
+**
+** Copyright (C) 2017 Mapbox, Inc.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtLocation module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qgeocodereplymapbox.h"
+#include "qmapboxcommon.h"
+
+#include <QtCore/QJsonDocument>
+#include <QtCore/QJsonObject>
+#include <QtCore/QJsonArray>
+#include <QtPositioning/QGeoCoordinate>
+#include <QtPositioning/QGeoAddress>
+#include <QtPositioning/QGeoLocation>
+#include <QtPositioning/QGeoRectangle>
+
+QT_BEGIN_NAMESPACE
+
+QGeoCodeReplyMapbox::QGeoCodeReplyMapbox(QNetworkReply *reply, QObject *parent)
+: QGeoCodeReply(parent)
+{
+ Q_ASSERT(parent);
+ if (!reply) {
+ setError(UnknownError, QStringLiteral("Null reply"));
+ return;
+ }
+
+ connect(reply, &QNetworkReply::finished, this, &QGeoCodeReplyMapbox::onNetworkReplyFinished);
+ connect(reply, QOverload<QNetworkReply::NetworkError>::of(&QNetworkReply::error),
+ this, &QGeoCodeReplyMapbox::onNetworkReplyError);
+
+ connect(this, &QGeoCodeReply::aborted, reply, &QNetworkReply::abort);
+ connect(this, &QObject::destroyed, reply, &QObject::deleteLater);
+}
+
+QGeoCodeReplyMapbox::~QGeoCodeReplyMapbox()
+{
+}
+
+void QGeoCodeReplyMapbox::onNetworkReplyFinished()
+{
+ QNetworkReply *reply = static_cast<QNetworkReply *>(sender());
+ reply->deleteLater();
+
+ if (reply->error() != QNetworkReply::NoError)
+ return;
+
+ QList<QGeoLocation> locations;
+ QJsonDocument document = QJsonDocument::fromJson(reply->readAll());
+ if (!document.isObject()) {
+ setError(ParseError, tr("Response parse error"));
+ return;
+ }
+
+ const QJsonArray features = document.object().value(QStringLiteral("features")).toArray();
+ for (const QJsonValue &value : features)
+ locations.append(QMapboxCommon::parseGeoLocation(value.toObject()));
+
+ setLocations(locations);
+
+ setFinished(true);
+}
+
+void QGeoCodeReplyMapbox::onNetworkReplyError(QNetworkReply::NetworkError error)
+{
+ Q_UNUSED(error)
+ QNetworkReply *reply = static_cast<QNetworkReply *>(sender());
+ reply->deleteLater();
+ setError(QGeoCodeReply::CommunicationError, reply->errorString());
+}
+
+QT_END_NAMESPACE
diff --git a/src/plugins/geoservices/mapbox/qgeocodereplymapbox.h b/src/plugins/geoservices/mapbox/qgeocodereplymapbox.h
new file mode 100644
index 00000000..156299fa
--- /dev/null
+++ b/src/plugins/geoservices/mapbox/qgeocodereplymapbox.h
@@ -0,0 +1,63 @@
+/****************************************************************************
+**
+** Copyright (C) 2017 Mapbox, Inc.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtLocation module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QGEOCODEREPLYMAPBOX_H
+#define QGEOCODEREPLYMAPBOX_H
+
+#include <QtNetwork/QNetworkReply>
+#include <QtLocation/QGeoCodeReply>
+
+QT_BEGIN_NAMESPACE
+
+class QGeoCodeReplyMapbox : public QGeoCodeReply
+{
+ Q_OBJECT
+
+public:
+ explicit QGeoCodeReplyMapbox(QNetworkReply *reply, QObject *parent = 0);
+ ~QGeoCodeReplyMapbox();
+
+private Q_SLOTS:
+ void onNetworkReplyFinished();
+ void onNetworkReplyError(QNetworkReply::NetworkError error);
+};
+
+QT_END_NAMESPACE
+
+#endif // QGEOCODEREPLYMAPBOX_H
diff --git a/src/plugins/geoservices/mapbox/qgeocodingmanagerenginemapbox.cpp b/src/plugins/geoservices/mapbox/qgeocodingmanagerenginemapbox.cpp
new file mode 100644
index 00000000..e0c4f6a5
--- /dev/null
+++ b/src/plugins/geoservices/mapbox/qgeocodingmanagerenginemapbox.cpp
@@ -0,0 +1,205 @@
+/****************************************************************************
+**
+** Copyright (C) 2017 Mapbox, Inc.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtLocation module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qgeocodingmanagerenginemapbox.h"
+#include "qgeocodereplymapbox.h"
+#include "qmapboxcommon.h"
+
+#include <QtCore/QVariantMap>
+#include <QtCore/QUrl>
+#include <QtCore/QUrlQuery>
+#include <QtCore/QLocale>
+#include <QtCore/QStringList>
+#include <QtNetwork/QNetworkAccessManager>
+#include <QtNetwork/QNetworkRequest>
+#include <QtNetwork/QNetworkReply>
+#include <QtPositioning/QGeoCoordinate>
+#include <QtPositioning/QGeoAddress>
+#include <QtPositioning/QGeoShape>
+#include <QtPositioning/QGeoCircle>
+#include <QtPositioning/QGeoRectangle>
+
+QT_BEGIN_NAMESPACE
+
+namespace {
+ static const QString allAddressTypes = QStringLiteral("address,district,locality,neighborhood,place,postcode,region,country");
+}
+
+QGeoCodingManagerEngineMapbox::QGeoCodingManagerEngineMapbox(const QVariantMap &parameters,
+ QGeoServiceProvider::Error *error,
+ QString *errorString)
+: QGeoCodingManagerEngine(parameters), m_networkManager(new QNetworkAccessManager(this))
+{
+ if (parameters.contains(QStringLiteral("mapbox.useragent")))
+ m_userAgent = parameters.value(QStringLiteral("mapbox.useragent")).toString().toLatin1();
+ else
+ m_userAgent = QByteArrayLiteral("Qt Location based application");
+
+ m_accessToken = parameters.value(QStringLiteral("mapbox.access_token")).toString();
+
+ m_isEnterprise = parameters.value(QStringLiteral("mapbox.enterprise")).toBool();
+ m_urlPrefix = m_isEnterprise ? mapboxGeocodingEnterpriseApiPath : mapboxGeocodingApiPath;
+
+ *error = QGeoServiceProvider::NoError;
+ errorString->clear();
+}
+
+QGeoCodingManagerEngineMapbox::~QGeoCodingManagerEngineMapbox()
+{
+}
+
+QGeoCodeReply *QGeoCodingManagerEngineMapbox::geocode(const QGeoAddress &address, const QGeoShape &bounds)
+{
+ QUrlQuery queryItems;
+
+ // If address text() is not generated: a manual setText() has been made.
+ if (!address.isTextGenerated()) {
+ queryItems.addQueryItem(QStringLiteral("type"), allAddressTypes);
+ return doSearch(address.text().simplified(), queryItems, bounds);
+ }
+
+ QStringList addressString;
+ QStringList typeString;
+
+ if (!address.street().isEmpty()) {
+ addressString.append(address.street());
+ typeString.append(QStringLiteral("address"));
+ }
+
+ if (!address.district().isEmpty()) {
+ addressString.append(address.district());
+ typeString.append(QStringLiteral("district"));
+ typeString.append(QStringLiteral("locality"));
+ typeString.append(QStringLiteral("neighborhood"));
+ }
+
+ if (!address.city().isEmpty()) {
+ addressString.append(address.city());
+ typeString.append(QStringLiteral("place"));
+ }
+
+ if (!address.postalCode().isEmpty()) {
+ addressString.append(address.postalCode());
+ typeString.append(QStringLiteral("postcode"));
+ }
+
+ if (!address.state().isEmpty()) {
+ addressString.append(address.state());
+ typeString.append(QStringLiteral("region"));
+ }
+
+ if (!address.country().isEmpty()) {
+ addressString.append(address.country());
+ typeString.append(QStringLiteral("country"));
+ }
+
+ queryItems.addQueryItem(QStringLiteral("type"), typeString.join(QLatin1Char(',')));
+ queryItems.addQueryItem(QStringLiteral("limit"), QString::number(1));
+
+ return doSearch(addressString.join(QStringLiteral(", ")), queryItems, bounds);
+}
+
+QGeoCodeReply *QGeoCodingManagerEngineMapbox::geocode(const QString &address, int limit, int offset, const QGeoShape &bounds)
+{
+ Q_UNUSED(offset)
+
+ QUrlQuery queryItems;
+ queryItems.addQueryItem(QStringLiteral("type"), allAddressTypes);
+ queryItems.addQueryItem(QStringLiteral("limit"), QString::number(limit));
+
+ return doSearch(address, queryItems, bounds);
+}
+
+QGeoCodeReply *QGeoCodingManagerEngineMapbox::reverseGeocode(const QGeoCoordinate &coordinate, const QGeoShape &bounds)
+{
+ const QString coordinateString = QString::number(coordinate.longitude()) + QLatin1Char(',') + QString::number(coordinate.latitude());
+
+ QUrlQuery queryItems;
+ queryItems.addQueryItem(QStringLiteral("limit"), QString::number(1));
+
+ return doSearch(coordinateString, queryItems, bounds);
+}
+
+QGeoCodeReply *QGeoCodingManagerEngineMapbox::doSearch(const QString &request, QUrlQuery &queryItems, const QGeoShape &bounds)
+{
+ queryItems.addQueryItem(QStringLiteral("access_token"), m_accessToken);
+
+ const QString &languageCode = QLocale::system().name().section(QLatin1Char('_'), 0, 0);
+ queryItems.addQueryItem(QStringLiteral("language"), languageCode);
+
+ QGeoRectangle boundingBox = bounds.boundingGeoRectangle();
+ if (!boundingBox.isEmpty()) {
+ queryItems.addQueryItem(QStringLiteral("bbox"),
+ QString::number(boundingBox.topLeft().longitude()) + QLatin1Char(',') +
+ QString::number(boundingBox.bottomRight().latitude()) + QLatin1Char(',') +
+ QString::number(boundingBox.bottomRight().longitude()) + QLatin1Char(',') +
+ QString::number(boundingBox.topLeft().latitude()));
+ }
+
+ QUrl requestUrl(m_urlPrefix + request + QStringLiteral(".json"));
+ requestUrl.setQuery(queryItems);
+
+ QNetworkRequest networkRequest(requestUrl);
+ networkRequest.setHeader(QNetworkRequest::UserAgentHeader, m_userAgent);
+
+ QNetworkReply *networkReply = m_networkManager->get(networkRequest);
+ QGeoCodeReplyMapbox *reply = new QGeoCodeReplyMapbox(networkReply, this);
+
+ connect(reply, &QGeoCodeReplyMapbox::finished, this, &QGeoCodingManagerEngineMapbox::onReplyFinished);
+ connect(reply, QOverload<QGeoCodeReply::Error, const QString &>::of(&QGeoCodeReply::error),
+ this, &QGeoCodingManagerEngineMapbox::onReplyError);
+
+ return reply;
+}
+
+void QGeoCodingManagerEngineMapbox::onReplyFinished()
+{
+ QGeoCodeReply *reply = qobject_cast<QGeoCodeReply *>(sender());
+ if (reply)
+ emit finished(reply);
+}
+
+void QGeoCodingManagerEngineMapbox::onReplyError(QGeoCodeReply::Error errorCode, const QString &errorString)
+{
+ QGeoCodeReply *reply = qobject_cast<QGeoCodeReply *>(sender());
+ if (reply)
+ emit error(reply, errorCode, errorString);
+}
+
+QT_END_NAMESPACE
diff --git a/src/plugins/geoservices/mapbox/qgeocodingmanagerenginemapbox.h b/src/plugins/geoservices/mapbox/qgeocodingmanagerenginemapbox.h
new file mode 100644
index 00000000..614151f5
--- /dev/null
+++ b/src/plugins/geoservices/mapbox/qgeocodingmanagerenginemapbox.h
@@ -0,0 +1,83 @@
+/****************************************************************************
+**
+** Copyright (C) 2017 Mapbox, Inc.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtLocation module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QGEOCODINGMANAGERENGINEMAPBOX_H
+#define QGEOCODINGMANAGERENGINEMAPBOX_H
+
+#include <QtCore/QUrlQuery>
+#include <QtLocation/QGeoServiceProvider>
+#include <QtLocation/QGeoCodingManagerEngine>
+#include <QtLocation/QGeoCodeReply>
+
+QT_BEGIN_NAMESPACE
+
+class QNetworkAccessManager;
+
+class QGeoCodingManagerEngineMapbox : public QGeoCodingManagerEngine
+{
+ Q_OBJECT
+
+public:
+ QGeoCodingManagerEngineMapbox(const QVariantMap &parameters, QGeoServiceProvider::Error *error,
+ QString *errorString);
+ ~QGeoCodingManagerEngineMapbox();
+
+ QGeoCodeReply *geocode(const QGeoAddress &address, const QGeoShape &bounds) Q_DECL_OVERRIDE;
+ QGeoCodeReply *geocode(const QString &address, int limit, int offset,
+ const QGeoShape &bounds) Q_DECL_OVERRIDE;
+ QGeoCodeReply *reverseGeocode(const QGeoCoordinate &coordinate,
+ const QGeoShape &bounds) Q_DECL_OVERRIDE;
+
+private slots:
+ void onReplyFinished();
+ void onReplyError(QGeoCodeReply::Error errorCode, const QString &errorString);
+
+private:
+ QGeoCodeReply *doSearch(const QString &, QUrlQuery &, const QGeoShape &bounds);
+
+ QNetworkAccessManager *m_networkManager;
+ QByteArray m_userAgent;
+ QString m_accessToken;
+ QString m_urlPrefix;
+ bool m_isEnterprise;
+};
+
+QT_END_NAMESPACE
+
+#endif // QGEOCODINGMANAGERENGINEMAPBOX_H
diff --git a/src/plugins/geoservices/mapbox/qgeoserviceproviderpluginmapbox.cpp b/src/plugins/geoservices/mapbox/qgeoserviceproviderpluginmapbox.cpp
index ff98c501..80d9098e 100644
--- a/src/plugins/geoservices/mapbox/qgeoserviceproviderpluginmapbox.cpp
+++ b/src/plugins/geoservices/mapbox/qgeoserviceproviderpluginmapbox.cpp
@@ -35,6 +35,7 @@
****************************************************************************/
#include "qgeoserviceproviderpluginmapbox.h"
+#include "qgeocodingmanagerenginemapbox.h"
#include "qgeotiledmappingmanagerenginemapbox.h"
#include "qgeoroutingmanagerenginemapbox.h"
#include "qplacemanagerenginemapbox.h"
@@ -43,22 +44,26 @@
QT_BEGIN_NAMESPACE
-QGeoCodingManagerEngine *QGeoServiceProviderFactoryMapbox::createGeocodingManagerEngine(
- const QVariantMap &parameters, QGeoServiceProvider::Error *error, QString *errorString) const
-{
- Q_UNUSED(parameters)
- Q_UNUSED(error)
- Q_UNUSED(errorString)
-
- return 0;
-}
-
static inline QString msgAccessTokenParameter()
{
return QGeoServiceProviderFactoryMapbox::tr("Mapbox plugin requires a 'mapbox.access_token' parameter.\n"
"Please visit https://www.mapbox.com");
}
+QGeoCodingManagerEngine *QGeoServiceProviderFactoryMapbox::createGeocodingManagerEngine(
+ const QVariantMap &parameters, QGeoServiceProvider::Error *error, QString *errorString) const
+{
+ const QString accessToken = parameters.value(QStringLiteral("mapbox.access_token")).toString();
+
+ if (!accessToken.isEmpty()) {
+ return new QGeoCodingManagerEngineMapbox(parameters, error, errorString);
+ } else {
+ *error = QGeoServiceProvider::MissingRequiredParameterError;
+ *errorString = msgAccessTokenParameter();
+ return 0;
+ }
+}
+
QGeoMappingManagerEngine *QGeoServiceProviderFactoryMapbox::createMappingManagerEngine(
const QVariantMap &parameters, QGeoServiceProvider::Error *error, QString *errorString) const
{
diff --git a/tests/auto/qgeoserviceprovider/tst_qgeoserviceprovider.cpp b/tests/auto/qgeoserviceprovider/tst_qgeoserviceprovider.cpp
index 8ac926d2..c21608b3 100644
--- a/tests/auto/qgeoserviceprovider/tst_qgeoserviceprovider.cpp
+++ b/tests/auto/qgeoserviceprovider/tst_qgeoserviceprovider.cpp
@@ -104,7 +104,9 @@ void tst_QGeoServiceProvider::tst_features_data()
QTest::newRow("mapbox") << QString("mapbox")
<< QGeoServiceProvider::MappingFeatures(QGeoServiceProvider::OnlineMappingFeature)
- << QGeoServiceProvider::GeocodingFeatures(QGeoServiceProvider::NoGeocodingFeatures)
+ << QGeoServiceProvider::GeocodingFeatures(QGeoServiceProvider::OnlineGeocodingFeature
+ | QGeoServiceProvider::ReverseGeocodingFeature
+ | QGeoServiceProvider::LocalizedGeocodingFeature)
<< QGeoServiceProvider::RoutingFeatures(QGeoServiceProvider::OnlineRoutingFeature)
<< QGeoServiceProvider::PlacesFeatures(QGeoServiceProvider::OnlinePlacesFeature
| QGeoServiceProvider::PlaceRecommendationsFeature