Created
May 26, 2015 03:26
-
-
Save DirleiDionisio/2336c067b8f3e5faa4da to your computer and use it in GitHub Desktop.
Routes with Apple Maps, Google Maps and Waze (iOS & Android)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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