How to launch navigation apps from your own app and sending variables

Posted By : Sapna Sharma | 20-Feb-2015

Sometimes it's your app’s requirement to launch navigation apps (like Waze). Any kind of communication/control between your own app and navigation app is possible using APIs . On iOS launch by url and on Android launch by intent.

 

Here I have shared an example to launch Waze app from your own app in Android and IOS using titanium framework. The following code will launch Waze to look for the specified location, if Waze is installed. If Waze is not installed, it will open Waze page on the Market application to install it.

Here is the code -

 

exports.NavigateTo = function(latitude, longitude){
    var url = 'waze://?ll='+latitude+','+longitude+'&navigate=yes';
    if (OS_ANDROID){
        try {
            Ti.API.info('Trying to Launch via Intent');
            var intent = Ti.Android.createIntent({
                action: Ti.Android.ACTION_VIEW,
                data: url
 
            });
            Ti.Android.currentActivity.startActivity(intent);
        } catch (e){
            Ti.API.info('Caught Error launching intent: '+e);
            exports.Install();
        }
    }else{
        if (Ti.Platform.canOpenURL(url)){
            Ti.Platform.openURL(url);
        } else {
            exports.Install();
        }
 
    }
 
};
 
 exports.Install = function(){
    var alert = Ti.UI.createAlertDialog({
        title: "Waze Not Installed",
        message: "This action requires you install the Waze application",
        buttonNames: [ "OK", "Cancel" ],
        cancel: 1
    });
 
    alert.addEventListener("click", function(_event) {
        if(_event.index === 0) {
            var installURL;
            if (OS_ANDROID){
                installURL = 'market://details?id=com.waze';
            } else {
                installurl = 'http://itunes.apple.com/us/app/id323229106';
            }
            Ti.API.info("Installing Waze application");
            Ti.Platform.openURL(installURL);
        } else {
            Ti.API.info("User aborted Waze installation");
        }
    });
 
    alert.show();
};
 

Thanks

About Author

Author Image
Sapna Sharma

Sapna is a bright Android Apps developer using Titanium framework. Sapna likes music and helping needy people.

Request for Proposal

Name is required

Comment is required

Sending message..