Commit e5998f8e authored by Volker Krause's avatar Volker Krause

Implement navigation on Android too

parent c9aa1dad
......@@ -66,7 +66,7 @@ void ApplicationController::showOnMap(const QVariant &place)
const auto activity = QtAndroid::androidActivity();
if (activity.isValid()) {
activity.callMethod<void>("showOnMap", "(Ljava/lang/String;)V", QAndroidJniObject::fromString(intentUri).object());
activity.callMethod<void>("launchViewIntentFromUri", "(Ljava/lang/String;)V", QAndroidJniObject::fromString(intentUri).object());
}
#else
......@@ -108,7 +108,29 @@ void ApplicationController::navigateTo(const QVariant& place)
return;
}
// TODO Android implementation
#ifdef Q_OS_ANDROID
const auto geo = JsonLdDocument::readProperty(place, "geo").value<GeoCoordinates>();
const auto addr = JsonLdDocument::readProperty(place, "address").value<PostalAddress>();
QString intentUri;
if (geo.isValid()) {
intentUri = QLatin1String("google.navigation:q=") + QString::number(geo.latitude())
+ QLatin1Char(',') + QString::number(geo.longitude());
} else if (!addr.isEmpty()) {
intentUri = QLatin1String("google.navigation:q=") + addr.streetAddress() + QLatin1String(", ")
+ addr.postalCode() + QLatin1Char(' ')
+ addr.addressLocality() + QLatin1String(", ")
+ addr.addressCountry();
} else {
return;
}
const auto activity = QtAndroid::androidActivity();
if (activity.isValid()) {
activity.callMethod<void>("launchViewIntentFromUri", "(Ljava/lang/String;)V", QAndroidJniObject::fromString(intentUri).object());
}
#else
if (!m_positionSource) {
m_positionSource = QGeoPositionInfoSource::createDefaultSource(this);
......@@ -127,6 +149,7 @@ void ApplicationController::navigateTo(const QVariant& place)
});
m_positionSource->requestUpdate();
}
#endif
}
void ApplicationController::navigateTo(const QGeoPositionInfo &from, const QVariant &to)
......
......@@ -59,11 +59,10 @@ public class Activity extends QtActivity
return tempFile.toString();
}
public void showOnMap(String uri)
public void launchViewIntentFromUri(String uri)
{
Uri mapIntentUri = Uri.parse(uri);
Intent mapIntent = new Intent(Intent.ACTION_VIEW, mapIntentUri);
mapIntent.setPackage("com.google.android.apps.maps");
startActivity(mapIntent);
}
}
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