I am developing an app using QML. I am trying to enable directions for a feature in the app by opening the device's mapping app.
For most Androids, this means opening up Google Maps. For iOS device's this could mean either opening Apple Maps OR Google Maps depending on which app the user has downloaded on their phone.
Is there code that will switch to Google Maps if Apple Maps is not installed on a users phone?
Here is my code that I have currently
MouseArea {
anchors.fill: parent
preventStealing: true
onClicked: {
if(app.enableDistance && app.showDistance && app.isOnline) {
var link = "http://maps.google.com?daddr="+address+"&saddr="+app.locationManager.latitude+","+app.locationManager.longitude+"&zoom=14&views=traffic&&directionsmode=driving&x-success=sourceapp://?resume=true"
if(Qt.platform.os == "ios") {
link = "http://maps.apple.com/?daddr=" + address + "&dirflg=d"
}
if(Qt.platform.os == "ios" || Qt.platform.os == "android") {
Qt.openUrlExternally(link)
}
}
}
}
These links work successfully as long as the user has either Google Maps installed on their Android device or Apple Maps installed on their iOS device. If a iOS user doesn't have Apple Maps, it prompts the user to download Apple Maps in the store.
Any tips would be helpful. Thanks!