import { openUrl } from "tns-core-modules/utils/utils" ; import { DirectionsApi , DirectionsCommon , NavigateToOptions } from "./directions.common" ; const isAppAvailable = require ( "nativescript-appavailability" ) . availableSync ; export class Directions extends DirectionsCommon implements DirectionsApi { public available ( ) { return Promise . resolve ( true ) ; } public navigate ( options ) { return new Promise < void > ( ( resolve , reject ) => { try { const fromToQs = Directions . getFromToQuerystring ( options ) ; if ( ( options . ios === undefined || options . ios . preferGoogleMaps !== false ) && isAppAvailable ( "comgooglemaps://" ) ) { openUrl ( "comgooglemaps://" + fromToQs ) ; } else if ( options . ios && options . ios . allowGoogleMapsWeb && options . to instanceof Array && options . to . length > 1 ) { openUrl ( "http://maps.google.com/maps" + fromToQs ) ; } else { openUrl ( "http://maps.apple.com/maps" + fromToQs ) ; } resolve ( ) ; } catch ( e ) { reject ( e ) ; } } ) ; } }