Android调起高德地图

一、Android打开高德地图的方法汇总
System.out.println("乘客端经纬度:" + mNaviTo.latitude + "," + mNaviTo.longitude);
/**
 * @param sourceApplication 必填 第三方调用应用名称。如 amap
 * @param poiname 非必填 POI 名称
 * @param lat 必填 纬度
 * @param lon 必填 经度
 * @param dev 必填 是否偏移(0:lat 和 lon 是已经加密后的,不需要国测加密; 1:需要国测加密)
 * @param style 必填 导航方式(0 速度快; 1 费用少; 2 路程短; 3 不走高速;4 躲避拥堵;5 不走高速且避免收费;6 不走高速且躲避拥堵;7 躲避收费和拥堵;8 不走高速躲避收费和拥堵))
 */

if (false) {
    //Uri mUri = Uri.parse("geo:" + mNaviTo.latitude + "," + mNaviTo.longitude + "?q=");

    Intent intent = null;
    try {
        intent = Intent.getIntent("androidamap://navi?sourceApplication=" + getString(R.string.app_name) + "&dname=aaaa&dlat=" + mNaviTo.latitude + "&dlon=" + mNaviTo.longitude + "&dev=1&style=0");
    } catch (URISyntaxException e) {
        e.printStackTrace();
    }
    // Intent intent = new Intent("android.intent.action.VIEW", mUri);
    startActivity(intent);
}
if (false) {
    StringBuffer stringBuffer = new StringBuffer("androidamap://navi?sourceApplication=")
            .append(getString(R.string.app_name)).append("&dlat=").append(mNaviTo.latitude)
            .append("&dlon=").append(mNaviTo.longitude)
            .append("&dev=").append(1)
            .append("&style=").append(0);
    Intent intent = new Intent(Intent.ACTION_VIEW, android.net.Uri.parse(stringBuffer.toString()));
    intent.addCategory(Intent.CATEGORY_DEFAULT);
    intent.setPackage("com.autonavi.minimap");
    startActivity(intent);
}

if (false) {
    Intent intent = null;
    try {
        intent = Intent.getIntent("androidamap://viewReGeo?sourceApplication=HQMC&lat=" + mNaviTo.latitude + "&lon=" + mNaviTo.longitude + "&dev=0");
    } catch (URISyntaxException e) {
        e.printStackTrace();
    }
    startActivity(intent); //启动调用
}

if (false) {

    try {
        Intent intent = Intent.getIntent("androidamap://route?sourceApplication=softname&sname=我的位置&dlat=" + mNaviTo.latitude + "&dlon=" + mNaviTo.longitude + "&dname=" + "东郡华城广场|A座" + "&dev=0&m=0&t=1");
        startActivity(intent); //启动调用
    } catch (URISyntaxException e) {
        e.printStackTrace();
    }
}

if (false) {
    Intent intent = new Intent("android.intent.action.VIEW",
            android.net.Uri.parse("androidamap://showTraffic?sourceApplication=softname&poiid=BGVIS1&lat=" + mNaviTo.latitude + "&lon=" + mNaviTo.longitude + "&level=10&dev=0"));
    intent.setPackage("com.autonavi.minimap");
    startActivity(intent);

}
if (true) {
    // 构造导航参数
    NaviPara naviPara = new NaviPara();
    // 设置终点位置
    naviPara.setTargetPoint(new LatLng(mNaviTo.latitude, mNaviTo.longitude));
    // 设置导航策略,这里是避免拥堵
    naviPara.setNaviStyle(com.amap.api.maps.AMapUtils.DRIVING_AVOID_CONGESTION);
    try {
        // 调起高德地图导航
        com.amap.api.maps.AMapUtils.openAMapNavi(naviPara, getContext().getApplicationContext());
    } catch (Exception e) {

    }

if (true) {//实现路线选择,多条路线可选择
    String uriString = null;
    StringBuilder builder = new StringBuilder("amapuri://route/plan?sourceApplication=maxuslife");

    builder.append("&dlat=").append(mNaviTo.latitude)
            .append("&dlon=").append(mNaviTo.longitude)
            .append("&dname=").append(mTvTopStart.getText().toString())
            .append("&dev=0")
            .append("&t=0");
    uriString = builder.toString();
    Intent intent = new Intent(Intent.ACTION_VIEW);
    intent.setPackage("com.autonavi.minimap");
    intent.setData(Uri.parse(uriString));
    startActivity(intent);

}
}

//调起百度地图

else if (msg.equals("百度地图")) {
    if (ToolKt.isAvilible(getContext(), "com.baidu.BaiduMap")) {
        LngLat lngLat = new LngLat(mNaviTo.longitude, mNaviTo.latitude);
        LngLat bd_encrypt = bd_encrypt(lngLat);
        StringBuilder builder = new StringBuilder("baidumap://map/direction?mode=driving&");
        builder.append("&destination=latlng:")
                .append(bd_encrypt.getLantitude())
                .append(",")
                .append(bd_encrypt.getLongitude())
                .append("|name:")
                .append(mTvTopStart.getText().toString());
        String uriString = builder.toString();
        Intent intent = new Intent(Intent.ACTION_VIEW);
        intent.setPackage("com.baidu.BaiduMap");
        intent.setData(Uri.parse(uriString));
        startActivity(intent);

    } else {
        toast("请安装百度地图");
    }

 

二、判断是否安装某个软件

/**
 * 判断是否安装某个软件
 */
fun isAvilible(context: Context, packageName: String): Boolean {
    //获取packagemanager
    val packageManager = context.packageManager
    //获取所有已安装程序的包信息
    val packages = packageManager.getInstalledPackages(0)
    //用于存储所有已安装程序的包名
    val arrayList = ArrayList()
    //从pinfo中将包名字逐一取出,压入pName list中
    if (packages != null) {
        for (p: PackageInfo in packages) {
            val p = p.packageName
            arrayList.add(p)
        }
    }
    //判断packageNames中是否有目标程序的包名,有TRUE,没有FALSE
    return arrayList.contains(packageName);
}

你可能感兴趣的:(Android)