欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

android 调用第三方地图导航

程序员文章站 2022-07-13 15:58:48
...
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);








相关标签: 导航

上一篇: 高德导航

下一篇: css导航