1. 程式人生 > >android 呼叫第三方地圖導航

android 呼叫第三方地圖導航

1、判斷手機是否安裝地圖軟體
public static boolean isAvilible(Context context, String packageName){
    //獲取packagemanager
final PackageManager packageManager = context.getPackageManager();
    //獲取所有已安裝程式的包資訊
List<PackageInfo> packageInfos = packageManager.getInstalledPackages(0);
    //用於儲存所有已安裝程式的包名
List<String> packageNames = new 
ArrayList<String>(); //從pinfo中將包名字逐一取出,壓入pName list中 if(packageInfos != null){ for(int i = 0; i < packageInfos.size(); i++){ String packName = packageInfos.get(i).packageName; packageNames.add(packName); } } //判斷packageNames中是否有目標程式的包名,有TRUE,沒有FALSE
return packageNames.contains(packageName); } 2、根據地圖軟體進行導航
double  latitudes=0.0;
double  longitude=0.0;
  private  void  goDanghang(){
        Intent intent;
        if(isAvilible(SmallDetailActivity.this,"com.baidu.BaiduMap")){//傳入指定應用包名
//                          intent = Intent.getIntent("intent://map/direction?origin=latlng:34.264642646862,108.95108518068|name:我家&destination=大雁塔&mode=driving®ion=西安&src=yourCompanyName|yourAppName#Intent;scheme=bdapp;package=com.baidu.BaiduMap;end");
StringBuffer stringBuffer = new StringBuffer("baidumap://map/navi?location=") .append(latitudes).append(",").append(longitude).append("&type=TIME"); intent = new Intent(Intent.ACTION_VIEW, Uri.parse(stringBuffer.toString())); intent.setPackage("com.baidu.BaiduMap"); startActivity(intent); }else if(isAvilible(SmallDetailActivity.this, "com.autonavi.minimap")){ StringBuffer stringBuffer = new StringBuffer("androidamap://navi?sourceApplication=") .append("yitu8_driver").append("&lat=").append(latitudes) .append("&lon=").append(longitude) .append("&dev=").append(1) .append("&style=").append(0); ; // if (!TextUtils.isEmpty(poiname)) { // stringBuffer.append("&poiname=").append(poiname); // } Intent intent1 = new Intent(Intent.ACTION_VIEW, android.net.Uri.parse(stringBuffer.toString())); intent1.addCategory(Intent.CATEGORY_DEFAULT); intent1.setPackage("com.autonavi.minimap"); startActivity(intent1); }else if (isAvilible(SmallDetailActivity.this,"com.google.android.apps.maps")){//網頁版的 StringBuffer stringBuffer = new StringBuffer("google.navigation:q=").append(latitudes).append(",").append(longitude).append("&mode=d"); Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(stringBuffer.toString())); i.setPackage("com.google.android.apps.maps"); startActivity(i); } else{//未安裝 //market為路徑,id為包名 //顯示手機上所有的market商店 showToast("您尚未安裝地圖軟體"); // Uri uri = Uri.parse("market://details?id=com.baidu.BaiduMap"); // intent = new Intent(Intent.ACTION_VIEW, uri); // startActivity(intent); }
 /**
     * 開啟google Web地圖導航
     */
    private void openWebGoogleNavi() {
        StringBuffer stringBuffer = new StringBuffer("http://ditu.google.cn/maps?hl=zh&mrt=loc&q=").append(lat).append(",").append(lng);
        Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(stringBuffer.toString()));
        startActivity(i);
    }
跳轉商店:轉載https://blog.csdn.net/siwujidan0125/article/details/53214895
(1)百度地圖
//market為路徑,id為包名  
//顯示手機上所有的market商店  
Toast.makeText(context, "您尚未安裝百度地圖", Toast.LENGTH_LONG).show();
Uri uri = Uri.parse("market://details?id=com.baidu.BaiduMap");  
Intent intent = new Intent(Intent.ACTION_VIEW, uri);   
startActivity(intent);   
(2)高德地圖
Toast.makeText(context, "您尚未安裝高德地圖", Toast.LENGTH_LONG).show();
Uri uri = Uri.parse("market://details?id=com.autonavi.minimap");  
Intent intent = new Intent(Intent.ACTION_VIEW, uri);   
startActivity(intent);
(3)Google地圖
Toast.makeText(context, "您尚未安裝谷歌地圖", Toast.LENGTH_LONG).show();
Uri uri = Uri.parse("market://details?id=com.google.android.apps.maps");  
Intent intent = new Intent(Intent.ACTION_VIEW, uri);   
startActivity(intent);