Created
October 20, 2017 13:33
-
-
Save joshualambert/ba5d6bbe98bc9b8124e8a04648df9d20 to your computer and use it in GitHub Desktop.
Titanium Navigation Function
This file contains 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
// Used to prompt a user for how to open an address, or open automatically, based on the platform. | |
function openAddress(destAddr, startAddr) { | |
var destParam = ''; | |
var startParam = ''; | |
if (typeof destAddr !== 'undefined') { | |
destParam = '&daddr=' + encodeURIComponent(destAddr); | |
} | |
if (typeof startAddr !== 'undefined') { | |
startParam = '&saddr=' + encodeURIComponent(startAddr); | |
} | |
if (OS_IOS) { // iOS. Prompt user if they want Apple Maps or Google Maps. | |
var infoDialog = Titanium.UI.createAlertDialog({ | |
title: 'Info', | |
message: 'Please select which map you want to use: ', | |
buttonNames: ['Google Maps', 'Apple Maps', 'Cancel'], | |
cancel:2 | |
}); | |
infoDialog.addEventListener('click', function(e) { | |
if (e.index === 1) { // Apple Maps was chosen. | |
Ti.Platform.openURL("http://maps.apple.com/?linkSrc=mobileApp" + startParam + destParam); | |
} else if (e.index === 0) { // Google Maps was chosen. | |
Ti.Platform.openURL("http://maps.google.com/maps?linkSrc=mobileApp" + startParam + destParam + '&dirflg=r&mra=ltm&t=m'); // Google Maps. | |
} | |
}); | |
infoDialog.show(); | |
} else if (OS_ANDROID) { // Android. Open Google Maps. | |
var mapIntent = Ti.Android.createIntent({ | |
action : Ti.Android.ACTION_VIEW, | |
data : "http://maps.google.com/maps?linkSrc=mobileApp" + startParam + destParam + '&dirflg=r&mra=ltm&t=m' | |
}); | |
Ti.Android.currentActivity.startActivity(mapIntent); | |
} else { // Unknown platform. Just open the browser to Google Maps. | |
Ti.Platform.openURL("http://maps.google.com/?linkSrc=mobileApp" + startParam + destParam + '&dirflg=r&mra=ltm&t=m'); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment