Android 应用内实现导航页面,接入百度SDK内置导航,高德SDK内置导航

1、首先到百度地图开放平台创建应用,获取应用AK

http://lbsyun.baidu.com/apiconsole/key

2、到百度语言平台创建应用,获取Secret Key和语言APP ID

http://yuyin.baidu.com/app

 

3、到百度地图开放平台下载Android 导航SDK

https://pan.baidu.com/s/1z1cSWmkcE8kHhAXUVL4Ebw

 

4、修改ak和sk 和APP ID 还有使用你的keystore打包即可完成百度内置导航接入

配置你的ak,sk

 

配置你的APP ID

 

 配置你的签名

 

 

demo 链接:https://pan.baidu.com/s/1z1cSWmkcE8kHhAXUVL4Ebw

密码:在线回复QQ1085220040

在线回复bug.QQ1085220040

 

运行即可:

 

2、高德地图内置导航实现——比集成百度内置导航方便,建议使用

 

申请key:https://lbs.amap.com/

 

实现demo:https://download.csdn.net/download/meixi_android/12704895 

 

在线bug交流:扣扣1085220040

 

package com.example.ampnavigation;import android.content.DialogInterface;
import android.graphics.Color;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.view.KeyEvent;import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;import com.amap.api.maps.model.Circle;
import com.amap.api.maps.model.CircleOptions;
import com.amap.api.maps.model.LatLng;
import com.amap.api.navi.AMapNavi;
import com.amap.api.navi.AMapNaviListener;
import com.amap.api.navi.AMapNaviView;
import com.amap.api.navi.AMapNaviViewListener;
import com.amap.api.navi.AMapNaviViewOptions;
import com.amap.api.navi.enums.NaviType;
import com.amap.api.navi.model.AMapCalcRouteResult;
import com.amap.api.navi.model.AMapLaneInfo;
import com.amap.api.navi.model.AMapModelCross;
import com.amap.api.navi.model.AMapNaviCameraInfo;
import com.amap.api.navi.model.AMapNaviCross;
import com.amap.api.navi.model.AMapNaviInfo;
import com.amap.api.navi.model.AMapNaviLocation;
import com.amap.api.navi.model.AMapNaviRouteNotifyData;
import com.amap.api.navi.model.AMapNaviTrafficFacilityInfo;
import com.amap.api.navi.model.AMapServiceAreaInfo;
import com.amap.api.navi.model.AimLessModeCongestionInfo;
import com.amap.api.navi.model.AimLessModeStat;
import com.amap.api.navi.model.NaviInfo;
import com.amap.api.navi.model.NaviLatLng;
import com.autonavi.tbt.TrafficFacilityInfo;import java.util.ArrayList;
import java.util.List;public class NaviActivity extends AppCompatActivity {private AMapNaviView mAMapNaviView;private AMapNavi mAMapNavi;protected AlertDialog.Builder builder;protected AlertDialog dialog;private String las,los;private int  fwint;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_navi);las = getIntent().getStringExtra("las");los = getIntent().getStringExtra("los");fwint = getIntent().getIntExtra("fw",0);//获取 AMapNaviView 实例mAMapNaviView = findViewById(R.id.navi_view);//获取AMapNavi实例mAMapNavi = AMapNavi.getInstance(getApplicationContext());
//        mAMapNavi.setUseInnerVoice(true);mAMapNavi.setUseInnerVoice(true,true);AMapNaviViewOptions options = mAMapNaviView.getViewOptions();//隐藏SDK默认的布局
//        options.setLayoutVisible(false);
//        options.setTrafficBarEnabled(true);mAMapNaviView.setViewOptions(options);mAMapNavi.setMultipleRouteNaviMode(true);mAMapNaviView.setAMapNaviViewListener(new AMapNaviViewListener() {@Overridepublic void onNaviSetting() {}@Overridepublic void onNaviCancel() {finish();Log.i("lgq","cancel");}@Overridepublic boolean onNaviBackClick() {Log.i("lgq","cancelback");showNavBackDialog();return true;}@Overridepublic void onNaviMapMode(int i) {}@Overridepublic void onNaviTurnClick() {}@Overridepublic void onNextRoadClick() {}@Overridepublic void onScanViewButtonClick() {}@Overridepublic void onLockMap(boolean b) {}@Overridepublic void onNaviViewLoaded() {}@Overridepublic void onMapTypeChanged(int i) {}@Overridepublic void onNaviViewShowMode(int i) {}});mAMapNaviView.onCreate(savedInstanceState);//添加监听回调,用于处理算路成功mAMapNavi.addAMapNaviListener(new AMapNaviListener() {@Overridepublic void onInitNaviFailure() {}@Overridepublic void onInitNaviSuccess() {final double startLatitude = 22.991262;final double startLongitude = 113.707716;final double targetLatitude = 23.001662;final double targetLongitude = 113.607816;//navigate(targetLatitude,targetLongitude);/*** 方法:*   int strategy=mAMapNavi.strategyConvert(congestion, avoidhightspeed, cost, hightspeed, multipleroute);* 参数:* @congestion 躲避拥堵* @avoidhightspeed 不走高速* @cost 避免收费* @hightspeed 高速优先* @multipleroute 多路径** 说明:*      以上参数都是boolean类型,其中multipleroute参数表示是否多条路线,如果为true则此策略会算出多条路线。* 注意:*      不走高速与高速优先不能同时为true*      高速优先与避免收费不能同时为true*/int strategy = 0;try {strategy = mAMapNavi.strategyConvert(true, false, false, false, false);} catch (Exception e) {e.printStackTrace();}List<NaviLatLng> sList = new ArrayList<NaviLatLng>() {{add(new NaviLatLng(startLatitude, startLongitude));}};List<NaviLatLng> eList = new ArrayList<NaviLatLng>() {{add(new NaviLatLng(targetLatitude, targetLongitude));}};List<NaviLatLng> mWayPointList = null;mAMapNavi.calculateDriveRoute(sList, eList, mWayPointList, strategy);/*绘制圆*/int alpha = 160;Circle circle = mAMapNaviView.getMap().addCircle(new CircleOptions().center(new LatLng(targetLatitude, targetLongitude)).radius(1000).fillColor(Color.argb(alpha, 10, 200, 1)).fillColor(Color.parseColor("#19999999")).strokeColor(Color.parseColor("#33df6e50")).strokeWidth(10));}@Overridepublic void onStartNavi(int i) {}@Overridepublic void onTrafficStatusUpdate() {}@Overridepublic void onLocationChange(AMapNaviLocation aMapNaviLocation) {}@Overridepublic void onGetNavigationText(int i, String s) {Log.i("lgq","文字啦啦啦   ====  "+s);}@Overridepublic void onGetNavigationText(String s) {Log.i("lgq","文字啦eeee啦啦   ====  "+s);}@Overridepublic void onEndEmulatorNavi() {}@Overridepublic void onArriveDestination() {}@Overridepublic void onCalculateRouteFailure(int i) {}@Overridepublic void onReCalculateRouteForYaw() {}@Overridepublic void onReCalculateRouteForTrafficJam() {}@Overridepublic void onArrivedWayPoint(int i) {}@Overridepublic void onGpsOpenStatus(boolean b) {}@Overridepublic void onNaviInfoUpdate(NaviInfo naviInfo) {}@Overridepublic void onNaviInfoUpdated(AMapNaviInfo aMapNaviInfo) {}@Overridepublic void updateCameraInfo(AMapNaviCameraInfo[] aMapNaviCameraInfos) {}@Overridepublic void updateIntervalCameraInfo(AMapNaviCameraInfo aMapNaviCameraInfo, AMapNaviCameraInfo aMapNaviCameraInfo1, int i) {}@Overridepublic void onServiceAreaUpdate(AMapServiceAreaInfo[] aMapServiceAreaInfos) {}@Overridepublic void showCross(AMapNaviCross aMapNaviCross) {}@Overridepublic void hideCross() {}@Overridepublic void showModeCross(AMapModelCross aMapModelCross) {}@Overridepublic void hideModeCross() {}@Overridepublic void showLaneInfo(AMapLaneInfo[] aMapLaneInfos, byte[] bytes, byte[] bytes1) {}@Overridepublic void showLaneInfo(AMapLaneInfo aMapLaneInfo) {}@Overridepublic void hideLaneInfo() {}@Overridepublic void onCalculateRouteSuccess(int[] ints) {mAMapNavi.startNavi(NaviType.GPS);}@Overridepublic void notifyParallelRoad(int i) {}@Overridepublic void OnUpdateTrafficFacility(AMapNaviTrafficFacilityInfo aMapNaviTrafficFacilityInfo) {}@Overridepublic void OnUpdateTrafficFacility(AMapNaviTrafficFacilityInfo[] aMapNaviTrafficFacilityInfos) {}@Overridepublic void OnUpdateTrafficFacility(TrafficFacilityInfo trafficFacilityInfo) {}@Overridepublic void updateAimlessModeStatistics(AimLessModeStat aimLessModeStat) {}@Overridepublic void updateAimlessModeCongestionInfo(AimLessModeCongestionInfo aimLessModeCongestionInfo) {}@Overridepublic void onPlayRing(int i) {}@Overridepublic void onCalculateRouteSuccess(AMapCalcRouteResult aMapCalcRouteResult) {}@Overridepublic void onCalculateRouteFailure(AMapCalcRouteResult aMapCalcRouteResult) {}@Overridepublic void onNaviRouteNotify(AMapNaviRouteNotifyData aMapNaviRouteNotifyData) {}});Handler handler = new Handler();handler.postDelayed(new Runnable() {@Overridepublic void run() {mAMapNavi.startSpeak();}}, 500);}@Overrideprotected void onResume() {super.onResume();
//        mAMapNavi.startNavi(1);mAMapNaviView.onResume();}@Overrideprotected void onPause() {super.onPause();mAMapNaviView.onPause();}@Overrideprotected void onDestroy() {super.onDestroy();mAMapNaviView.onDestroy();mAMapNavi.destroy();mAMapNavi=null;Log.i("lgqddddddddddddddd","dddddddd33");}@Overridepublic boolean onKeyDown(int keyCode, KeyEvent event) {if (keyCode == KeyEvent.KEYCODE_BACK) {showNavBackDialog();return true;}return super.onKeyDown(keyCode, event);}/**** 返回按钮 dialog提示*/private void showNavBackDialog() {builder = new AlertDialog.Builder(this);builder.setTitle("提示");builder.setMessage("确定退出导航?");builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {@Overridepublic void onClick(DialogInterface dialogInterface, int i) {}});builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {@Overridepublic void onClick(DialogInterface dialogInterface, int i) {finish();}});dialog = builder.show();}/**** 回收dialog*/private void dismissDialog(){if(dialog != null){if(dialog.isShowing()){dialog.dismiss();}dialog = null;}builder = null;}
}

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/414683.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

6、Flutter Error waiting for a debug connection: ProcessException: adb did not report f(转)

1、错误信息 Error waiting for a debug connection: ProcessException: adb did not report forwarded port 2、解决方法 升级adb&#xff0c;其实是更新SDK Platform-Tools就可以了。 步骤&#xff1a;打开 Android SDK >>> SDK Tools 勾选 Android SDK Flatform-…

前端学习(2710):重读vue电商网站30之左侧菜单栏图标设计

我们想要的效果如下&#xff1a; 如何设计&#xff1f; 首先&#xff0c;我们可以在 data 中定义一个对象&#xff0c;对应于每一个菜单选项的 id 然后通过 for 循环遍历每一个菜单选项的 id即可。

Android运行时异常 couldn't find xx.so

Android 关于导入module&#xff0c;运行时错误 java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/com.txjifei.mapclient.liteapp-fp0FTs4C57uV3aLogQRvYA/base.apk"],nativeLibraryDirectories[/data/app/com.txj…

4、jeecg 笔记之 自定义显示按钮 (exp 属性)

1、需求 先看一下需求吧&#xff0c;我们希望 datagrid 操作栏中的按钮&#xff0c;可以根据条件进行动态显示。 2、实现 其实 jeecg 提供了一个属性 - exp &#xff0c;通过该属性即可实现。 <t:dgFunOpt funname"startInspect(id,mcaPhone)" exp"mcaStatus…

AngularJs自学心得

1.angularjs的SEO问题解决方案 我的前端用到angularjs&#xff0c;服务器用到nginx。 大体流程&#xff1a; nginx服务器检测到爬虫访问&#xff0c;跳转到专门的url&#xff0c;此url是angularjs已经渲染过后的页面。非常的简单。 a).首先是angularjs的渲染问题 angular添加一…

Android 人脸识别进行实名验证demo

实名验证简介&#xff1a;http://ai.baidu.com/docs#/Face-PersonVerify-V3/top 1、首先到百度云平台——人脸识别项创建应用 https://console.bce.baidu.com/?fromai1#/aip/overview 2、创建应用之后、下载SDK SDK链接&#xff1a;https://download.csdn.net/download/meix…

Hibernate 补充 ManyToOne、OneToMany、OneToOne的使用例

1、前言 Hibernate 为程序员提供一种级联操作&#xff0c;在编写程序时&#xff0c;通过 Hibernate 的级联功能可以很方便的操作数据库的主从表的数据&#xff0c;我们最常用的级联是级联保存和级联删除。2、ManyToOne | OneToMany 单词误导 当我们去试用的时候&#xff0c;首先…

移动端使用页尾文字使用绝对定位遇到input框会飘起来的处理方案

如下版权信息的样式在遇到input框的时候会跟随输入框其后 优雅的解决方式&#xff1a;&#xff08;定位遇上键盘飘窗解决&#xff09; mounted里面写上&#xff1a;var originalHeightdocument.documentElement.clientHeight || document.body.clientHeight; //console.info(&…

Android 解决导入多个module时jar包冲突

1、在后导入的module中编译先前导入的module compile project(path: :faceplatform) 2、删除后导入的module里面的和先前导入的module的重复jar包&#xff0c; 同理jniLibs里面重复的so文件也需要删除 在线回复bug:qq1085220040

linux 添加环境变量(php为例)

find / -name php vim /etc/profile 文件最后添加 export PATH$PATH:/usr/local/php/bin source /etc/profile php -v 这时只实现了当前ssh 登录时可以PHP&#xff0c;如果退出重新登录就不能使用PHP了 解决&#xff1a; vim ~/.bashrc 添加 source /etc/profile source ~/.…

Android 活体人脸实时采集,百度、虹软

百度现在功能较少——使用虹软&#xff0c;方便 虹软官网&#xff1a;https://ai.arcsoft.com.cn/ucenter/resource/build/index.html 申请应用&#xff0c;下载SDK即可 虹软已修改好的&#xff0c;可注册人脸&#xff0c;人脸验证成功——登陆的demo&#xff1a;https://down…

Android 最新左右可见上下页的banner实现demo

运行效果&#xff0c;可见上下页样式 demo链接&#xff1a;https://download.csdn.net/download/meixi_android/11045703 实现方法 首先添加必要依赖 implementation (com.android.support:recyclerview-v7:27.0.2){force true } implementation (com.android.support:cardv…