2017-03-20 16:38:14 -04:00
import { Injectable } from '@angular/core' ;
import { Cordova , Plugin } from '@ionic-native/core' ;
2016-07-17 19:58:46 +02:00
2016-04-29 23:56:49 -04:00
export interface LaunchNavigatorOptions {
2016-03-06 15:08:19 -05:00
/**
2016-07-17 04:43:12 -04:00
* name of the navigation app to use for directions. Specify using launchnavigator.APP constants. If not specified, defaults to User Selection.
2016-03-06 15:08:19 -05:00
*/
2016-07-17 04:43:12 -04:00
app? : string ;
2016-03-06 15:08:19 -05:00
/**
2016-07-17 04:43:12 -04:00
* nickname to display in app for destination. e.g. "Bob's House".
2016-03-06 15:08:19 -05:00
*/
2016-07-17 04:43:12 -04:00
destinationName? : string ;
2016-03-06 15:08:19 -05:00
/**
2016-07-17 04:43:12 -04:00
* Start point of the navigation
2016-03-06 15:08:19 -05:00
*/
2016-07-17 19:58:46 +02:00
start? : string | number [ ] ;
2016-03-06 15:08:19 -05:00
/**
2016-07-17 04:43:12 -04:00
* nickname to display in app for start . e.g. "My House".
2016-03-06 15:08:19 -05:00
*/
2016-07-17 04:43:12 -04:00
startName? : string ;
2016-03-06 15:08:19 -05:00
/**
2016-07-17 04:43:12 -04:00
* Transportation mode for navigation: "driving", "walking" or "transit". Defaults to "driving" if not specified.
2016-03-06 15:08:19 -05:00
*/
2016-07-17 04:43:12 -04:00
transportMode? : string ;
2016-03-06 15:08:19 -05:00
/**
* If true, debug log output will be generated by the plugin. Defaults to false.
*/
2016-04-29 23:56:49 -04:00
enableDebug? : boolean ;
2016-03-06 15:08:19 -05:00
/**
2016-07-17 04:43:12 -04:00
* a key/value map of extra app-specific parameters. For example, to tell Google Maps on Android to display Satellite view in "maps" launch mode: `{"t": "k"}`
2016-03-06 15:08:19 -05:00
*/
2016-07-17 04:43:12 -04:00
extras? : any ;
2016-03-06 15:08:19 -05:00
2016-07-17 04:07:51 -04:00
/**
2016-07-17 04:43:12 -04:00
* (Android only) mode in which to open Google Maps app: "maps" or "turn-by-turn". Defaults to "maps" if not specified. Specify using launchnavigator.LAUNCH_MODE constants.
2016-07-17 04:07:51 -04:00
*/
2016-07-17 04:43:12 -04:00
launchMode? : string ;
/**
* text to display in the native picker which enables user to select which navigation app to launch. Defaults to "Select app for navigation" if not specified.
*/
appSelectionDialogHeader? : string ;
2016-07-17 04:07:51 -04:00
2016-07-17 04:43:12 -04:00
/**
* text to display for the cancel button in the native picker which enables user to select which navigation app to launch. Defaults to "Cancel" if not specified.
*/
appSelectionCancelButton? : string ;
2016-07-17 04:53:50 -04:00
successCallback? : Function ;
errorCallback? : Function ;
2016-03-06 15:08:19 -05:00
}
/**
2016-03-13 15:45:07 -04:00
* @name Launch Navigator
2016-03-12 18:30:16 -05:00
* @description
2016-03-06 15:08:19 -05:00
* Requires Cordova plugin: uk.co.workingedge.phonegap.plugin.launchnavigator. For more info, please see the [LaunchNavigator plugin docs](https://github.com/dpa99c/phonegap-launch-navigator).
*
* @usage
2016-07-17 04:43:12 -04:00
* Please refer to the plugin's repo for detailed usage. This docs page only explains the Native wrapper.
2016-07-17 04:53:50 -04:00
*
2016-07-20 17:17:09 +02:00
* ```typescript
2017-03-20 16:38:14 -04:00
* import { LaunchNavigator, LaunchNavigatorOptions } from '@ionic-native/launch-navigator';
*
* constructor(private launchNavigator: LaunchNavigator) { }
*
* ...
2016-03-24 13:00:18 -04:00
*
2016-07-17 04:43:12 -04:00
* let options: LaunchNavigatorOptions = {
* start: 'London, ON',
* app: LaunchNavigator.APPS.UBER
* };
2016-03-24 13:00:18 -04:00
*
2017-03-20 16:38:14 -04:00
* this.launchNavigator.navigate('Toronto, ON', options)
2016-03-06 15:11:19 -05:00
* .then(
2016-07-20 17:17:09 +02:00
* success => console.log('Launched navigator'),
* error => console.log('Error launching navigator', error)
2016-03-06 15:11:19 -05:00
* );
2016-03-06 15:08:19 -05:00
* ```
2016-12-06 09:20:49 -05:00
* @interfaces
* LaunchNavigatorOptions
2016-03-06 15:08:19 -05:00
*/
@Plugin ( {
2016-10-27 12:48:50 -05:00
pluginName : 'LaunchNavigator' ,
2016-03-12 18:30:16 -05:00
plugin : 'uk.co.workingedge.phonegap.plugin.launchnavigator' ,
pluginRef : 'launchnavigator' ,
2017-03-28 08:24:04 -04:00
repo : 'https://github.com/dpa99c/phonegap-launch-navigator' ,
platforms : [ 'Android' , 'iOS' ]
2016-03-06 15:08:19 -05:00
} )
2017-03-20 16:38:14 -04:00
@Injectable ( )
2016-03-06 15:08:19 -05:00
export class LaunchNavigator {
/**
* Launches navigator app
2016-07-17 04:43:12 -04:00
* @param destination {string|number[]} Location name or coordinates (as string or array)
2016-07-17 04:07:51 -04:00
* @param options {LaunchNavigatorOptions}
2016-03-06 15:08:19 -05:00
* @returns {Promise<any>}
*/
@Cordova ( {
2016-07-17 04:07:51 -04:00
successIndex : 1 ,
errorIndex : 2
2016-03-06 15:08:19 -05:00
} )
2017-03-20 16:38:14 -04:00
navigate (
2016-07-17 19:58:46 +02:00
destination : string | number [ ] ,
2016-04-29 23:56:49 -04:00
options? : LaunchNavigatorOptions
2016-07-17 19:58:46 +02:00
) : Promise < any > { return ; }
2016-03-06 15:08:19 -05:00
2016-07-17 04:43:12 -04:00
/**
* Determines if the given app is installed and available on the current device.
* @param app {string}
2016-11-29 16:40:50 -06:00
* @returns {Promise<any>}
2016-07-17 04:43:12 -04:00
*/
@Cordova ( )
2017-03-20 16:38:14 -04:00
isAppAvailable ( app : string ) : Promise < any > { return ; }
2016-07-17 04:43:12 -04:00
/**
* Returns a list indicating which apps are installed and available on the current device.
2016-11-29 16:40:50 -06:00
* @returns {Promise<string[]>}
2016-07-17 04:43:12 -04:00
*/
@Cordova ( )
2017-03-20 16:38:14 -04:00
availableApps ( ) : Promise < string [ ] > { return ; }
2016-07-17 04:43:12 -04:00
/**
* Returns the display name of the specified app.
* @param app {string}
2016-11-29 16:40:50 -06:00
* @returns {string}
2016-07-17 04:43:12 -04:00
*/
2016-07-17 19:58:46 +02:00
@Cordova ( { sync : true } )
2017-03-20 16:38:14 -04:00
getAppDisplayName ( app : string ) : string { return ; }
2016-07-17 04:43:12 -04:00
/**
* Returns list of supported apps on a given platform.
* @param platform {string}
2016-11-29 16:40:50 -06:00
* @returns {string[]}
2016-07-17 04:43:12 -04:00
*/
2016-07-17 19:58:46 +02:00
@Cordova ( { sync : true } )
2017-03-20 16:38:14 -04:00
getAppsForPlatform ( platform : string ) : string [ ] { return ; }
2016-07-17 04:43:12 -04:00
/**
* Indicates if an app on a given platform supports specification of transport mode.
* @param app {string} specified as a string, you can use one of the constants, e.g `LaunchNavigator.APP.GOOGLE_MAPS`
* @param platform {string}
2016-11-29 16:40:50 -06:00
* @returns {boolean}
2016-07-17 04:43:12 -04:00
*/
2016-07-17 19:58:46 +02:00
@Cordova ( { sync : true } )
2017-03-20 16:38:14 -04:00
supportsTransportMode ( app : string , platform : string ) : boolean { return ; }
2016-07-17 04:43:12 -04:00
/**
* Returns the list of transport modes supported by an app on a given platform.
* @param app {string}
* @param platform {string}
2016-11-29 16:40:50 -06:00
* @returns {string[]}
2016-07-17 04:43:12 -04:00
*/
2016-07-17 19:58:46 +02:00
@Cordova ( { sync : true } )
2017-03-20 16:38:14 -04:00
getTransportModes ( app : string , platform : string ) : string [ ] { return ; }
2016-07-17 04:43:12 -04:00
/**
* Indicates if an app on a given platform supports specification of launch mode.
* Note that currently only Google Maps on Android does.
* @param app {string}
* @param platform {string}
2016-11-29 16:40:50 -06:00
* @returns {boolean}
2016-07-17 04:43:12 -04:00
*/
2016-07-17 19:58:46 +02:00
@Cordova ( { sync : true } )
2017-03-20 16:38:14 -04:00
supportsLaunchMode ( app : string , platform : string ) : boolean { return ; }
2016-07-17 04:43:12 -04:00
/**
* Indicates if an app on a given platform supports specification of start location.
* @param app {string}
* @param platform {string}
2016-11-29 16:40:50 -06:00
* @returns {boolean}
2016-07-17 04:43:12 -04:00
*/
2016-07-17 19:58:46 +02:00
@Cordova ( { sync : true } )
2017-03-20 16:38:14 -04:00
supportsStart ( app : string , platform : string ) : boolean { return ; }
2016-07-17 04:43:12 -04:00
2016-11-29 16:40:50 -06:00
/**
* @param app {string}
* @param platform {string}
* @returns {boolean}
*/
2016-07-17 19:58:46 +02:00
@Cordova ( { sync : true } )
2017-03-20 16:38:14 -04:00
supportsStartName ( app : string , platform : string ) : boolean { return ; }
2016-07-17 04:43:12 -04:00
2016-11-29 16:40:50 -06:00
/**
* @param app {string}
* @param platform {string}
* @returns {boolean}
*/
2016-07-17 19:58:46 +02:00
@Cordova ( { sync : true } )
2017-03-20 16:38:14 -04:00
supportsDestName ( app : string , platform : string ) : boolean { return ; }
2016-07-17 04:43:12 -04:00
2016-11-29 16:40:50 -06:00
/**
* @param destination {string | number[]}
* @param options {LaunchNavigatorOptions}
*/
2016-07-17 19:58:46 +02:00
@Cordova ( { sync : true } )
2017-03-20 16:38:14 -04:00
userSelect ( destination : string | number [ ] , options : LaunchNavigatorOptions ) : void { }
2016-07-17 04:43:12 -04:00
2017-03-20 16:38:14 -04:00
APP : any = {
2016-07-17 04:43:12 -04:00
USER_SELECT : 'user_select' ,
APPLE_MAPS : 'apple_maps' ,
GOOGLE_MAPS : 'google_maps' ,
WAZE : 'waze' ,
CITYMAPPER : 'citymapper' ,
NAVIGON : 'navigon' ,
TRANSIT_APP : 'transit_app' ,
YANDEX : 'yandex' ,
UBER : 'uber' ,
TOMTOM : 'tomtom' ,
BING_MAPS : 'bing_maps' ,
SYGIC : 'sygic' ,
HERE_MAPS : 'here_maps' ,
MOOVIT : 'moovit'
} ;
2017-03-20 16:38:14 -04:00
TRANSPORT_MODE : any = {
2016-07-17 04:43:12 -04:00
DRIVING : 'driving' ,
WALKING : 'walking' ,
BICYCLING : 'bicycling' ,
TRANSIT : 'transit'
} ;
2016-03-06 15:08:19 -05:00
}