Android中直接打开高德APP进行导航
生活随笔
收集整理的這篇文章主要介紹了
Android中直接打开高德APP进行导航
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
1、判斷是否安裝有高德APP
//高德APP
private PackageManager mPackageManager;
private static List<String> mPackageNames = new ArrayList<>();
private static final String GAODE_PACKAGE_NAME = "com.autonavi.minimap";
private static final String BAIDU_PACKAGE_NAME = "com.baidu.BaiduMap";
/*private double currLocationX = 39.9076860000;
private double currLocationY = 116.4012450000;
private double locationX = 40.0836620000;
private double locationY = 116.4127900000;
private String storeName = "北京飯店";*/
private double currLocationX;//起點 緯度
private double currLocationY;//起點 經度
private double locationX;//終點 緯度
private double locationY;//終點 經度
private String storeName;//地點名稱
if(haveGaodeMap()){//如果安裝高德APP openGaodeMapToGuide();//打開高德APP } else {//否則 打開瀏覽器 openBrowserToGuide(); }
2、
/**
* 打開高德地圖
* https://lbs.amap.com/api/amap-mobile/guide/android/route
*/
private void openGaodeMapToGuide() {
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.addCategory(Intent.CATEGORY_DEFAULT);
Log.i("高德定位:","經度:"+currLocationY+" ,緯度:"+currLocationX);
if (currLocationX == 0.0 || currLocationY == 0.0){
url = "androidamap://route?sourceApplication=amap&dlat="+locationX+"&dlon="+locationY+"&dname="+storeName+"&dev=0&t=1";
}else {
url = "androidamap://route?sourceApplication=amap&slat="+currLocationX+"&slon="+currLocationY
+"&dlat="+locationX+"&dlon="+locationY+"&dname="+storeName+"&dev=0&t=1";
}
Uri uri = Uri.parse(url);
//將功能Scheme以URI的方式傳入data
intent.setData(uri);
//啟動該頁面即可
startActivity(intent);
}
/**
* 打開瀏覽器
*/
private void openBrowserToGuide() {
String url = "http://uri.amap.com/navigation?to=" + locationY + "," + locationX + "," +
storeName + "&mode=car&policy=1&src=mypage&coordinate=gaode&callnative=0";
Uri uri = Uri.parse(url);
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);
}
public void initPackageManager(){
List<PackageInfo> packageInfos = mPackageManager.getInstalledPackages(0);
if (packageInfos != null) {
for (int i = 0; i < packageInfos.size(); i++) {
mPackageNames.add(packageInfos.get(i).packageName);
}
}
}
/**
* 判斷有無安裝高德
* @return
*/
public boolean haveGaodeMap(){
initPackageManager();
return mPackageNames.contains(GAODE_PACKAGE_NAME);
}
總結
以上是生活随笔為你收集整理的Android中直接打开高德APP进行导航的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 学习:跳转指令
- 下一篇: Vue 2 难点汇总