In ionic3, open a third-party map and navigate to Baidu autonavi

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.