国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > Android > 正文

Android仿微信調用第三方地圖應用導航(高德、百度、騰訊)

2019-10-22 18:25:23
字體:
來源:轉載
供稿:網友

實現目標

先來一張微信功能截圖看看要做什么

Android微信調用第三方地圖,Android微信調用地圖應用導航,Android,第三方地圖應用導航

其實就是有一個目的地,點擊目的地的時候彈出可選擇的應用進行導航。

大腦動一下,要實現這個功能應該大體分成兩步:

  • 底部彈出可選的地圖菜單進行展示
  • 點擊具體菜單某一項的時候調用對應地圖的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;    }  }

效果圖

貼一下效果圖

Android微信調用第三方地圖,Android微信調用地圖應用導航,Android,第三方地圖應用導航

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持VEVB武林網。


注:相關教程知識閱讀請移步到Android開發頻道。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 偃师市| 易门县| 锡林浩特市| 雷州市| 冕宁县| 凌源市| 锡林浩特市| 勃利县| 东辽县| 衢州市| 达孜县| 磴口县| 西平县| 龙山县| 文昌市| 临安市| 黄骅市| 绵阳市| 城口县| 班玛县| 团风县| 颍上县| 搜索| 容城县| 新田县| 高唐县| 平泉县| 连城县| 桦南县| 东阿县| 穆棱市| 皮山县| 申扎县| 黔南| 静宁县| 九龙县| 宁武县| 宁海县| 罗田县| 崇仁县| 安陆市|