1. Install plug-ins that check for third-party apps
Cordova plugin add Cordova-plugin-appavailability -- save
NPM install -- save @ ionic-native/APP-availability. You can choose to install a fixed version number based on the project version compatibility. What I installed is @ 3.4.2.
Introduce appavailability on the page and make judgments because the package names of iOS and Android are different.
Import {appavailability} from '@ ionic-native/APP-availability'; // check whether the application is installed.
Import {platform} from 'ionic-angular ';
Constructor (Public appavailability: appavailability, private platform: Platform ,){}
Ionviewdidload (){
// Check whether Baidu map exists
If (this. Platform. Is ('ios ')){
This. baiduapp = 'baidumap ://';
} Else if (this. Platform. Is ('android ')){
This. baiduapp = 'com. Baidu. baidumap ';
}
This. appavailability. Check (this. baiduapp)
. Then (
(Yes: Boolean) =>{// you have installed the app.
Alert (this. baiduapp + 'is available ')
},
(No: Boolean) =>{// no app is installed
Alert (this. baiduapp + 'is not available ')
}
);
// Check whether AMAP exists
If (this. Platform. Is ('ios ')){
This. gaodeapp = 'autonavimap ://';
} Else if (this. Platform. Is ('android ')){
This. gaodeapp = 'com. autonavi. minimap ';
}
This. appavailability. Check (this. gaodeapp)
. Then (
(Yes: Boolean) =>{// you have installed the app.
Alert (this. gaodeapp + 'is available ')
},
(No: Boolean) =>{// no app is installed
Alert (this. gaodeapp + 'is not available ')
}
);
}
2. Install plug-ins that open third-party apps
Cordova plugin add https://github.com/lampaa/com.lampa.startapp.git
After the installation is successful, you can start to use it.
Declare var Startapp; // declare it at the beginning of the page
// Jump to Baidu Map
Gobaidumap (){
// Baidu map parameter configuration
Let baiduapp = Startapp. Set (
{
"Action": "action_view ",
"Category": "category_default ",
"Type": "text/CSS ",
"Package": This. baiduapp,
"Uri": "baidumap: // MAP/geocoder? Location = "+ this. Location. Coordinates [1] +", "+ this. Location. Coordinates [0] +" & src = Android. Baidu. openapidemo ",
"Flags": ["flag_activity_clear_top", "flag_activity_clear_task"],
"Intentstart": "startactivity ",
}, {/* Extras */
"Extra_stream": "extravalue1 ",
"Extrakey2": "extravalue2"
}
);
Baiduapp. Start (function (){
// Alert ('Baidu OK ')
}, Function (error ){
Alert (error)
})
};
// Jump to AMAP
Gogaodemap (){
// Configure AMAP Parameters
Let gaodeapp = Startapp. Set (
{
"Action": "action_view ",
"Category": "category_default ",
"Type": "text/CSS ",
"Package": This. gaodeapp,
"Uri": "androidamap: // viewmap? Sourceapplication = appname & poiname = "+ this. item. work_address + "& lat =" + this. location. coordinates [1] + "& Lon =" + this. location. coordinates [0] + "& Dev = 0 ",
"Flags": ["flag_activity_clear_top", "flag_activity_clear_task"],
"Intentstart": "startactivity ",
}, {/* Extras */
"Extra_stream": "extravalue1 ",
"Extrakey2": "extravalue2"
}
);
Gaodeapp. Start (function (){
// Alert ('gaode OK ')
}, Function (error ){
Alert (error)
})
}
The preceding URI parameters can be used for navigation, map tagging, route planning, and so on.
The first is latitude and the second is longitude.
For details, refer to the link
Baidu: http://lbsyun.baidu.com/index.php? Title = uri/API/Android autonavi: https://lbs.amap.com/api/amap-mobile/guide/android/navigation
In ionic3, open a third-party map and navigate to Baidu autonavi