Commit 4a44457d authored by Volker Krause's avatar Volker Krause

Add API for navigating from a given location rather than the current one

Not implemented for Android yet.
parent dc261e25
......@@ -21,6 +21,7 @@
#include "reservationmanager.h"
#include <KItinerary/JsonLdDocument>
#include <KItinerary/LocationUtil>
#include <KItinerary/Place>
#include <QClipboard>
......@@ -265,7 +266,7 @@ void ApplicationController::navigateTo(const QGeoPositionInfo &from, const QVari
return;
}
const auto geo = JsonLdDocument::readProperty(to, "geo").value<GeoCoordinates>();
const auto geo = LocationUtil::geo(to);
if (geo.isValid()) {
QUrl url;
url.setScheme(QStringLiteral("https"));
......@@ -282,6 +283,37 @@ void ApplicationController::navigateTo(const QGeoPositionInfo &from, const QVari
}
#endif
void ApplicationController::navigateTo(const QVariant& from, const QVariant& to)
{
#ifdef Q_OS_ANDROID
// TODO Android can't do this by default, but we can do osmand API calls directly
Q_UNUSED(from);
navigateTo(to);
#else
const auto fromGeo = LocationUtil::geo(from);
if (!fromGeo.isValid()) {
navigateTo(to);
return;
}
const auto toGeo = LocationUtil::geo(to);
if (!toGeo.isValid()) {
return;
}
QUrl url;
url.setScheme(QStringLiteral("https"));
url.setHost(QStringLiteral("www.openstreetmap.org"));
url.setPath(QStringLiteral("/directions"));
QUrlQuery query;
query.addQueryItem(QLatin1String("route"),
QString::number(fromGeo.latitude()) + QLatin1Char(',') + QString::number(fromGeo.longitude())
+ QLatin1Char(';') + QString::number(toGeo.latitude()) + QLatin1Char(',') + QString::number(toGeo.longitude()));
url.setQuery(query);
QDesktopServices::openUrl(url);
#endif
}
#ifdef Q_OS_ANDROID
void ApplicationController::importFromIntent(const QAndroidJniObject &intent)
{
......
......@@ -46,6 +46,7 @@ public:
Q_INVOKABLE void showOnMap(const QVariant &place);
Q_INVOKABLE bool canNavigateTo(const QVariant &place);
Q_INVOKABLE void navigateTo(const QVariant &place);
Q_INVOKABLE void navigateTo(const QVariant &from, const QVariant &to);
// data import
Q_INVOKABLE void showImportFileDialog();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment