import ReactNative from "react-native" ; param { string } location returns { Promise . < boolean > } export async function NavigateTo ( location ? ) { if ( ! location ) { return Promise . reject ( new Error ( "Input parameter 'Location' is required" ) ) ; } location = encodeURIComponent ( location ) ; const iosUrl = `maps://maps.apple.com/?daddr=${ location }` ; const androidUrl = `google.navigation:q=${ location }` ; const webUrl = `https://maps.google.com/maps?daddr=${ location }` ; if ( navigator && navigator . product === "ReactNative" ) { const Linking = require ( "react-native" ) . Linking ; const Platform = require ( "react-native" ) . Platform ; const url = Platform . select ( { ios : iosUrl , default : androidUrl } ) ; return Linking . canOpenURL ( url ) . then ( supported => { if ( ! supported ) { return false ; } return Linking . openURL ( url ) . then ( ( ) => true ) ; } ) ; } if ( window && window . navigator . userAgent ) { if ( /iPad|iPhone|iPod/i . test ( window . navigator . userAgent ) ) { openUrl ( iosUrl ) ; return Promise . resolve ( true ) ; } if ( /android|sink/i . test ( window . navigator . userAgent ) ) { openUrl ( androidUrl ) ; return Promise . resolve ( true ) ; } } if ( window ) { window . location . href = webUrl ; return Promise . resolve ( true ) ; } return Promise . resolve ( false ) ; function openUrl ( url ) { if ( window && window . cordova ) { window . open ( url , "_system" ) ; } if ( window ) { window . location . href = url ; } } }