Android仿微信調(diào)用第三方地圖應(yīng)用導(dǎo)航(高德、百度、騰訊)
實(shí)現(xiàn)目標(biāo)
先來一張微信功能截圖看看要做什么
其實(shí)就是有一個目的地,點(diǎn)擊目的地的時候彈出可選擇的應(yīng)用進(jìn)行導(dǎo)航。
大腦動一下,要實(shí)現(xiàn)這個功能應(yīng)該大體分成兩步:
- 底部彈出可選的地圖菜單進(jìn)行展示
- 點(diǎn)擊具體菜單某一項(xiàng)的時候調(diào)用對應(yīng)地圖的api進(jìn)行導(dǎo)航就ok啦
底部菜單這里用PopupWindow來做。
實(shí)現(xiàn)
1、菜單顯示
PopupWindow支持傳入view進(jìn)行彈出展示,所有我們直接寫一個菜單布局,高德、百度、騰訊 再加一個取消。
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就可以了。
然后在需要調(diào)用的地方顯示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、點(diǎn)擊每個菜單調(diào)用對用地圖的導(dǎo)航api
這個每個地圖的官網(wǎng)都會有介紹,你只需要把目的地名稱,經(jīng)緯度信息傳過去就好了,沒什么多說的,直接貼代碼。
@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")) {//傳入指定應(yīng)用包名 try { Intent intent = Intent.getIntent("intent://map/direction?" + "destination=latlng:" + mInfo.getLat() + "," + mInfo.getLng() + "|name:我的目的地" + //終點(diǎn) "&mode=driving&" + //導(dǎo)航路線方式 "&src=appname#Intent;scheme=bdapp;package=com.baidu.BaiduMap;end"); startActivity(intent); //啟動調(diào)用 } catch (URISyntaxException e) { Log.e("intent", e.getMessage()); } } else {//未安裝 //market為路徑,id為包名 //顯示手機(jī)上所有的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; } }
效果圖
貼一下效果圖
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- Android 百度地圖marker中圖片不顯示的解決方法(推薦)
- Android百度地圖添加Marker失真問題的解決方案
- 關(guān)于Android高德地圖的簡單開發(fā)實(shí)例代碼(DEMO)
- Android中GPS坐標(biāo)轉(zhuǎn)換為高德地圖坐標(biāo)詳解
- Android開發(fā)之高德地圖實(shí)現(xiàn)定位
- Android之高德地圖定位SDK集成及地圖功能實(shí)現(xiàn)
- Android 高德地圖之poi搜索功能的實(shí)現(xiàn)代碼
- GMap.Net開發(fā)之自定義Marker使用方法
- Android基于高德地圖完全自定義Marker的實(shí)現(xiàn)方法
相關(guān)文章
安裝時加入外部數(shù)據(jù)庫示例(android外部數(shù)據(jù)庫)
這篇文章主要介紹了android打包安裝時加入外部數(shù)據(jù)庫的示例,需要的朋友可以參考下2014-03-03Android Studio實(shí)現(xiàn)簡易進(jìn)制轉(zhuǎn)換計(jì)算器
這篇文章主要為大家詳細(xì)介紹了Android Studio實(shí)現(xiàn)簡易進(jìn)制轉(zhuǎn)換計(jì)算器,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-05-05AlertDialog點(diǎn)擊按鈕不消失的實(shí)現(xiàn)方法
我有一個文本輸入對話框,當(dāng)我點(diǎn)擊對話框上的“是”按鈕,它會驗(yàn)證輸入,然后關(guān)閉對話框,但是,如果輸入錯誤,我想停留在同一個對話框中。怎么實(shí)現(xiàn)此功能呢?下面通過本文給大家分享下2017-01-01Android EasyPermissions官方庫高效處理權(quán)限相關(guān)教程
Easypermissions簡化了Android M的運(yùn)行時權(quán)限的申請、結(jié)果處理、判斷等步驟。這篇文章主要介紹了Android EasyPermissions官方庫高效處理權(quán)限相關(guān)教程,需要的朋友可以參考下2017-11-11Android自定義view之太極圖的實(shí)現(xiàn)教程
這篇文章主要給大家介紹了關(guān)于Android自定義view之太極圖的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2021-01-01基于Android studio3.6的JNI教程之helloworld思路詳解
這篇文章主要介紹了基于Android studio3.6的JNI教程之helloworld,本文通過圖文實(shí)例代碼給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-03-03Android 開發(fā)系統(tǒng)自帶語音模塊應(yīng)用
本篇文章 主要介紹 Android 開發(fā)自帶語音模塊實(shí)例,在開發(fā)Android系統(tǒng)中會用到系統(tǒng)語音搜索模塊,這里給大家一個參考實(shí)例2016-07-07Android ScrollView實(shí)現(xiàn)向上滑動控件頂部懸浮效果
這篇文章主要為大家詳細(xì)介紹了Android ScrollView實(shí)現(xiàn)向上滑動控件頂部懸浮效果,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-05-05android開發(fā)教程之獲取使用當(dāng)前api的應(yīng)用程序名稱
開發(fā)手機(jī)安全管家的時候,比如要打電話,或者照相需要知道是哪個應(yīng)用程序在調(diào)用,就可以在API接口中調(diào)用下面的代碼2014-02-02