美文网首页安卓
安卓调起第三方地图

安卓调起第三方地图

作者: 远在远方的风yzyfdf | 来源:发表于2020-03-20 13:59 被阅读0次

    1.国内常用的三家地图软件

    • baidu("com.baidu.BaiduMap", "百度地图"),
    • gaode("com.autonavi.minimap", "高德地图"),
    • tengxun("com.tencent.map", "腾讯地图");

    2.判断地图软件是否安装

    public static boolean isAppInstalled(@NonNull final String pkgName) {
           PackageManager packageManager = Utils.getApp().getPackageManager();
           try {
                return packageManager.getApplicationInfo(pkgName, 0) != null;
           } catch (PackageManager.NameNotFoundException e) {
                e.printStackTrace();
                return false;
           }
    }
    

    3.打开地图标注指定地点

    private const val action = "android.intent.action.VIEW"
    private const val category = "android.intent.category.DEFAULT"
    

    1.百度

        fun goBaidumap(
            context: Context,
            poiname: String?,
            addr: String?,
            longitude: Double?,
            latitude: Double?
        ) {
            val naviIntent = Intent(
                action,
                Uri.parse("baidumap://map/marker?location=$latitude,$longitude&title=$poiname&content=$addr&coord_type=gcj02&traffic=on&src=$appname")
            ).apply {
                addCategory(category)
                setPackage(NavigationEnum.baidu.packageName)
            }
            context.startActivity(naviIntent)
        }
    

    2.高德

        fun goAmap(
            context: Context,
            poiname: String?,
            addr: String?,
            longitude: Double?,
            latitude: Double?
        ) {
            val naviIntent = Intent(
                action,
                Uri.parse("androidamap://viewMap?sourceApplication=$appname&poiname=$poiname&lat=$latitude&lon=$longitude&dev=0")
            ).apply {
                addCategory(category)
                setPackage(NavigationEnum.gaode.packageName)
            }
            context.startActivity(naviIntent)
        }
    

    3.腾讯

    fun goTencentmap(
            context: Context,
            poiname: String?,
            addr: String?,
            longitude: Double?,
            latitude: Double?
        ) {
            val naviIntent = Intent(
                action,
                Uri.parse("qqmap://map/marker?marker=coord:$latitude,$longitude;title:$poiname;addr:$addr&referer=$appname")
            ).apply {
                addCategory(category)
                setPackage(NavigationEnum.tengxun.packageName)
            }
            context.startActivity(naviIntent)
        }
    

    4.弹窗就自己写一个吧

    Screenshot_2020-03-20-13-48-32-937.jpg

    相关文章

      网友评论

        本文标题:安卓调起第三方地图

        本文链接:https://www.haomeiwen.com/subject/xsljyhtx.html