实现目标

先来一张微信功能截图看看要做什么 

其实就是有一个目的地,点击目的地的时候弹出可选择的应用进行导航。

大脑动一下,要实现这个功能应该大体分成两步:

  1. 底部弹出可选的地图菜单进行展示
  2. 点击具体菜单某一项的时候调用对应地图的api进行导航就ok啦

底部菜单这里用PopupWindow来做。

实现

1、菜单显示 
PopupWindow支持传入view进行弹出展示,所有我们直接写一个菜单布局,高德、百度、腾讯 再加一个取消。

map_navagation_sheet.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"> <Button
android:id="@+id/baidu_btn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/ulz_white_selector"
android:text="百度地图"/>
<include layout="@layout/common_line_view"/> <Button
android:id="@+id/gaode_btn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/ulz_white_selector"
android:text="高德地图"/>
<include layout="@layout/common_line_view"/>
<Button
android:id="@+id/tencent_btn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/ulz_white_selector"
android:text="腾讯地图"/>
<include layout="@layout/common_line_view"/>
<Button
android:id="@+id/cancel_btn2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/ulz_white_selector"
android:text="取消"/>
</LinearLayout>

这里为了显示效果,自己写了个PopupWindow的子类,一般你直接用PopupWindow就可以了。

然后在需要调用的地方显示PopupWindow


mapSheetView = LayoutInflater.from(this).inflate(R.layout.map_navagation_sheet, null); mBottomSheetPop = new BottomSheetPop(this);
mBottomSheetPop.setWidth(ViewGroup.LayoutParams.MATCH_PARENT);
mBottomSheetPop.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT);
mBottomSheetPop.setContentView(mapSheetView);
mBottomSheetPop.setBackgroundDrawable(new ColorDrawable(0x00000000));
mBottomSheetPop.setOutsideTouchable(true);
mBottomSheetPop.setFocusable(true);
mBottomSheetPop.showAtLocation(this.getWindow().getDecorView(), Gravity.BOTTOM, 0, 0);

2、点击每个菜单调用对用地图的导航api 
这个每个地图的官网都会有介绍,你只需要把目的地名称,经纬度信息传过去就好了,没什么多说的,直接贴代码。

@Override
public void onClick(View view) {
switch (view.getId()) {
case R.id.navigation_btn:
mBottomSheetPop = new BottomSheetPop(this);
mBottomSheetPop.setWidth(ViewGroup.LayoutParams.MATCH_PARENT);
mBottomSheetPop.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT);
mBottomSheetPop.setContentView(mapSheetView);
mBottomSheetPop.setBackgroundDrawable(new ColorDrawable(0x00000000));
mBottomSheetPop.setOutsideTouchable(true);
mBottomSheetPop.setFocusable(true);
mBottomSheetPop.showAtLocation(this.getWindow().getDecorView(), Gravity.BOTTOM, 0, 0);
break;
case R.id.cancel_btn2:
if (mBottomSheetPop != null) {
mBottomSheetPop.dismiss();
}
break;
case R.id.baidu_btn:
if (isAvilible(this, "com.baidu.BaiduMap")) {//传入指定应用包名
try {
Intent intent = Intent.getIntent("intent://map/direction?" +
"destination=latlng:" + mInfo.getLat() + "," + mInfo.getLng() + "|name:我的目的地" + //终点
"&mode=driving&" + //导航路线方式
"&src=appname#Intent;scheme=bdapp;package=com.baidu.BaiduMap;end");
startActivity(intent); //启动调用
} catch (URISyntaxException e) {
Log.e("intent", e.getMessage());
}
} else {//未安装
//market为路径,id为包名
//显示手机上所有的market商店
Toast.makeText(this, "您尚未安装百度地图", Toast.LENGTH_LONG).show();
Uri uri = Uri.parse("market://details?id=com.baidu.BaiduMap");
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
if (intent.resolveActivity(getPackageManager()) != null){
startActivity(intent);
}
}
mBottomSheetPop.dismiss();
break;
case R.id.gaode_btn:
if (isAvilible(this, "com.autonavi.minimap")) {
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.addCategory(Intent.CATEGORY_DEFAULT); //将功能Scheme以URI的方式传入data
Uri uri = Uri.parse("androidamap://navi?sourceApplication=appname&poiname=fangheng&lat=" + mInfo.getLat() + "&lon=" + mInfo.getLng() + "&dev=1&style=2");
intent.setData(uri); //启动该页面即可
startActivity(intent);
} else {
Toast.makeText(this, "您尚未安装高德地图", Toast.LENGTH_LONG).show();
Uri uri = Uri.parse("market://details?id=com.autonavi.minimap");
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
if (intent.resolveActivity(getPackageManager()) != null){
startActivity(intent);
}
}
mBottomSheetPop.dismiss();
break;
case R.id.tencent_btn:
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.addCategory(Intent.CATEGORY_DEFAULT); //将功能Scheme以URI的方式传入data
Uri uri = Uri.parse("qqmap://map/routeplan?type=drive&to=我的目的地&tocoord=" + mInfo.getLat() + "," + mInfo.getLng());
intent.setData(uri);
if (intent.resolveActivity(getPackageManager()) != null) {
//启动该页面即可
startActivity(intent);
} else {
Toast.makeText(this, "您尚未安装腾讯地图", Toast.LENGTH_LONG).show();
}
mBottomSheetPop.dismiss();
break;
}
}

效果图

贴一下效果图 

转载自:http://www.cnblogs.com/yihoudangxian/p/7680502.html

Android 仿微信调用第三方应用导航(百度,高德、腾讯)的更多相关文章

  1. ionic3 应用内打开第三方地图导航 百度 高德

    1.安装检测第三方APP是否存在的插件 cordova plugin add cordova-plugin-appavailability --save npm install --save @ion ...

  2. Android仿微信图片上传,可以选择多张图片,缩放预览,拍照上传等

    仿照微信,朋友圈分享图片功能 .可以进行图片的多张选择,拍照添加图片,以及进行图片的预览,预览时可以进行缩放,并且可以删除选中状态的图片 .很不错的源码,大家有需要可以下载看看 . 微信 微信 微信 ...

  3. Android 仿微信小视频录制

    Android 仿微信小视频录制 WechatShortVideo和WechatShortVideo文章

  4. [置顶] android利用jni调用第三方库——第三篇——编写库android程序整合第三方库libhello.so到自己的库libhelloword.so

    0:前言: 在第二篇中,我们主要介绍了丙方android公司利用乙方C++公司给的动态库,直接调用库中的方法,但是这样方式受限于: 乙方C++公司开发的动态库是否符合jni的规范,如果不规范,则不能直 ...

  5. [置顶] android利用jni调用第三方库——第二篇——编写库android程序直接调用第三方库libhello.so

    0:前言 1:本文主要作为丙方android公司的身份来写 2:作者有不对的地方,请指出,谢谢 [第一篇:android利用jni调用第三方库——编写库libhello.so] [第二篇:androi ...

  6. android调用第三方库——第二篇——编写库android程序直接调用第三方库libhello.so (转载)

    转自:http://blog.csdn.net/jiuyueguang/article/details/9449737 版权声明:本文为博主原创文章,未经博主允许不得转载. 0:前言 1:本文主要作为 ...

  7. 微信h5页面调用第三方位置导航

    微信h5页面拉起第三方导航应用 需要准备的: 通过微信认证的公众号有备案过的域名 背景:微信公众号点击菜单栏跳到h5页面,需要用到导航功能 需求:当用户点击导航按钮时,跳转到第三方app进行导航 参考 ...

  8. Android仿微信高效压缩图片(libjpeg)

    用过ios手机的同学应该很明显感觉到,ios拍照1M的图片要比安卓拍照排出来的5M的图片还要清晰.这是为什么呢? 这得了解android底层是如何对图片进行处理的. 当时谷歌开发Android的时候, ...

  9. Android通过微信实现第三方登录并使用OKHttp获得Token及源码下载

    这里对于App在微信开放平台上申请AppID和secret在这里就略过了,我们微信的授权登录流程,腾讯官网给的流程如下: 1. 第三方发起微信授权登录请求,微信用户允许授权第三方应用后,微信会拉起应用 ...

随机推荐

  1. DELPHI异步选择模型UDP

    unit U_FrmServer; interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Di ...

  2. ASPNET Core 部署 Linux — 使用 Jexus Web Server

    第一步 安装.Net Core环境 安装 dotnet 环境参见官方网站 https://www.microsoft.com/net/core. 选择对应的系统版本进行安装.安装完成过后 输入命令查看 ...

  3. 小白学开发(iOS)OC_ 字符串的获取 (2015-08-11)

    // //  main.m //  字符串的获取 // //  Created by admin on 15/8/13. //  Copyright (c) 2015年 admin. All righ ...

  4. python可变參数调用函数问题

    一直使用python实现一些想法,近期在使用python的过程中出现这样一个需求,定义了一个函数.第一个是普通參数.第二个是默认參数,后面还有可变參数,在最初学习python的时候,都知道非keywo ...

  5. ios网络学习------11 原生API文件上传之断点续传思路

    watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvaHVhbmcyMDA5MzAzNTEz/font/5a6L5L2T/fontsize/400/fill/I0 ...

  6. 11种常见sqlmap使用方法

    sqlmap是渗透中常用的一个注入工具,其实在注入工具方面,一个sqlmap就足够用了,只要你用的熟,秒杀各种工具,只是一个便捷性问题. 一.SQLMAP用于Access数据库注入 (1) 猜解是否能 ...

  7. 删除子节点XML数据

    XmlDocument xDoc = new XmlDocument(); xDoc.Load(txtValueHelper.txtValue); XmlNodeList list = xDoc.Se ...

  8. Bridge Page

    http://www.zzbaike.com/wiki/%E6%A1%A5%E9%A1%B5 桥页(Bridge Page),又叫“门页”(Doorway/Portal/Jump/Entry Page ...

  9. 在MAC端查看win7

    在MAC端查看win7,在finder中打开网络,输入win7地址,填入用户名和密码,就可以了

  10. J20170528-ts

    断片 片断 くどい     啰嗦 アノテーション 注释 annotation