Skip to content

Instantly share code, notes, and snippets.

@DirleiDionisio
Created June 27, 2015 21:27
Show Gist options
  • Save DirleiDionisio/85e1d3eb87801bb3bc89 to your computer and use it in GitHub Desktop.
Save DirleiDionisio/85e1d3eb87801bb3bc89 to your computer and use it in GitHub Desktop.
Routes
mapview.addEventListener('click', function(e) {
//var source = '-23.504158,-46.834677';
var source = userLatitude + ',' + userLongitude;
Ti.API.info('source: ' + source + ' | dest: ' + e.annotation.latitude + ',' + e.annotation.longitude);
if (OS_IOS && e.clicksource == "rightButton") {
var dialog = Ti.UI.createOptionDialog({
title: 'Utilizar...',
cancel: 3,
options: ['Apple Maps', 'Google Maps', 'Waze', 'Cancelar'],
});
dialog.show();
dialog.addEventListener('click', function(e_dlg) {
if (e_dlg.index === 0) {
Ti.Platform.openURL('https://maps.apple.com/?daddr=' + e.annotation.latitude + ',' + e.annotation.longitude + '&saddr=' + source);
} else if (e_dlg.index === 1) {
if (!Ti.Platform.openURL('comgooglemaps://?saddr=' + source + '&daddr=' + e.annotation.latitude + ',' + e.annotation.longitude)) {
Ti.Platform.openURL("https://itunes.apple.com/br/app/id585027354");
};
} else if (e_dlg.index === 2) {
if (!Ti.Platform.openURL('waze://?ll=' + e.annotation.latitude + ',' + e.annotation.longitude + '&navigate=yes')) {
Ti.Platform.openURL("http://itunes.apple.com/br/app/id323229106");
};
}
});
} else if (OS_ANDROID && e.clicksource == "rightPane") {
var dialog = Ti.UI.createOptionDialog({
title: 'Utilizar...',
options: ['Mapa padrão', 'Modo navegação (novo)', 'Waze'],
});
dialog.show();
dialog.addEventListener('click', function(e_dlg) {
if (e_dlg.index === 0) {
if (!Ti.Platform.openURL('http://maps.google.com/maps?daddr=' + e.annotation.latitude + ',' + e.annotation.longitude + '&saddr=' + source)) {
Ti.Platform.openURL('market://details?id=com.google.android.apps.maps');
};
} else if (e_dlg.index === 1) {
if (!Ti.Platform.openURL('google.navigation:q=' + e.annotation.latitude + ',' + e.annotation.longitude)) {
Ti.Platform.openURL('market://details?id=com.google.android.apps.maps');
};
} else if (e_dlg.index === 2) {
if (!Ti.Platform.openURL('waze://?q=' + e.annotation.latitude + ',' + e.annotation.longitude)) {
Ti.Platform.openURL('market://details?id=com.waze');
};
}
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment