Android地图跳转

 

在开发中通常用到地图跳转,选择地址之后跳转到对应的地图,如图:

Android地图跳转_第1张图片

 

对应的跳转方法在地图对应官方的SDk文档中都可以找到:

  • 百度地图

http://lbsyun.baidu.com/index.php?title=uri/api/android

  • 腾讯地址

https://lbs.qq.com/webApi/uriV1/uriGuide/uriMobileRoute

  • 高德地图

https://lbs.amap.com/api/amap-mobile/guide/android/navigation

一、判断地图是否安装

根据包名判断是否安装,对应的包名如下:

    public static boolean isInstalled(String packageName,Context cxt) {
        final PackageManager packageManager = ctx.getPackageManager();
        List pinfo = packageManager.getInstalledPackages(0);
        List pName = new ArrayList<>();
        if (pinfo != null) {
            for (int i = 0; i < pinfo.size(); i++) {
                String pn = pinfo.get(i).packageName;
                pName.add(pn);
            }
        }
        return pName.contains(packageName);
    }
  • 百度地图:com.baidu.BaiduMap
  • 腾讯地图: com.tencent.map
  • 高德地图:com.autonavi.minimap

二、地图对应的跳转方法

下面介绍携带参数经纬度或者address跳转的方法:

1、百度地图

    public static void baiduMap(Activity activity, String lat, String lon) {
        if (AppUtils.isInstalled(("com.baidu.BaiduMap"))) {
            Intent intent = new Intent();
            intent.setData(Uri.parse("baidumap://map/show?center=" + lat + "," + lon +
                    "&zoom=11" +
                    "&coord_type=gcj02" +
                    "&traffic=off" +
                    "&src=" + appid));
            activity.startActivity(intent);
        }
    }

2、腾讯地图

腾讯地图的跳转需要到官网上申请AppKey才能完成跳转,腾讯地图AppKey申请十分简单,秒申请。

    public static void tencentMap(Activity activity, String lat, String lon, String address) {
        if (AppUtils.isInstalled(("com.tencent.map"))) {
            Intent intent = new Intent();
            intent.setData(Uri.parse("qqmap://map/marker?marker=coord:" + lat + "," + lon +
                    ";addr:" + address +
                    "&referer=appkey"));
            activity.startActivity(intent);
        }
    }

3、高德地图

    public static void gaodeMap(Activity activity, String lat, String lon, String address) {
        if (AppUtils.isInstalled("com.autonavi.minimap")) {
            Intent intent = new Intent();
            intent.setAction(Intent.ACTION_VIEW);
            intent.addCategory(Intent.CATEGORY_DEFAULT);
            intent.setPackage("com.autonavi.minimap");
            intent.setData(Uri.parse("androidamap://viewMap?sourceApplication=" + UIUtils.getString(R.string.app_name) +
                    "&poiname=" + address +
                    "&lat=" + lat +
                    "&lon=" + lon +
                    "&dev=0" +
                    "&pkg=" + Appid
            ));
            activity.startActivity(intent);
        }
    }

 

你可能感兴趣的:(android,android,地图)