百度地图sdk导航
文章目录
前言
公司要用到百度地图sdk的专业导航,让写个flutter插件。。。。
我负责android原生导航😁
在此记录
提示:以下是本篇文章正文内容,下面案例可供参考
一、准备
官方文档
https://lbsyun.baidu.com/index.php?title=android-navsdk/guide/projectConfiguration
根据文档配置权限,配置ak
二、下载demo
点击相关下载
把下面这两个都下载下来
解压
三、配置
将上面libs的复制到下面的目录(我有x86和x86_64因为之前同事写了地图插件🐓)
导入这两个aar
导入过程
然后finish
1.配置build.gradle(两个不同的)
代码如下(示例):
android {
compileSdkVersion 29
defaultConfig {
minSdkVersion 16
}
lintOptions {
disable 'InvalidPackage'
}
sourceSets {
main {
//我加入的-------
jniLibs.srcDir 'libs'
//------------
}
}
}
dependencies {
implementation files('libs/BaiduLBS_Android.jar')
implementation files('libs/okio-1.13.0.jar')
implementation files('libs/okhttp-3.8.1.jar')
implementation files('libs/bos-android-sdk-1.0.3.jar')
implementation files('libs/BaiduTraceSDK_v3_1_7.jar')
implementation files('libs/intellij_annotations.jar')
implementation files('libs/javapoet-1.9.0.jar')
implementation files('libs/protobuf-java-2.3.0-micro.jar')
implementation files('libs/protobuf_gens-map.jar')
implementation project(':onsdk_all')
//我加入的-------
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:cardview-v7:28.0.0'
implementation 'com.android.support:recyclerview-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
//----------
implementation project(':NaviTts')
}
android {
compileSdkVersion 29
lintOptions {
disable 'InvalidPackage'
}
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.dyys.baidumap.plugin.flutter_baidumap_plugin_example"
minSdkVersion 18
targetSdkVersion 29
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
//我加入的----------------
// 避免"64K 引用限制"
multiDexEnabled true
// 导航SDK内部使用了annotationProcessor,需要添加下面代码,防止编译异常
javaCompileOptions {
annotationProcessorOptions {
includeCompileClasspath = true }}
//-----------------------------
}
buildTypes {
release {
// TODO: Add your own signing config for the release build.
// Signing with the debug keys for now, so `flutter run --release` works.
signingConfig signingConfigs.debug
}
}
2.打开apk试玩
看源码找到需要的demo界面(我:专业导航)(已改好)
DemoGuideActivity.java
/*
* Copyright (C) 2018 Baidu, Inc. All Rights Reserved.
*/
package com.dyys.baidumap.plugin.flutter_baidumap_plugin.activity;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.util.Log;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import com.baidu.navisdk.adapter.BNaviCommonParams;
import com.baidu.navisdk.adapter.BaiduNaviManagerFactory;
import com.baidu.navisdk.adapter.IBNRouteGuideManager;
import com.baidu.navisdk.adapter.IBNTTSManager;
import com.baidu.navisdk.adapter.IBNaviListener;
import com.baidu.navisdk.adapter.IBNaviViewListener;
import com.baidu.navisdk.adapter.struct.BNGuideConfig;
import com.baidu.navisdk.adapter.struct.BNHighwayInfo;
import com.baidu.navisdk.adapter.struct.BNRoadCondition;
import com.baidu.navisdk.adapter.struct.BNaviInfo;
import com.baidu.navisdk.adapter.struct.BNaviLocation;
import com.baidu.navisdk.ui.routeguide.model.RGLineItem;
import java.util.List;
/**
* 诱导界面
*/
public class DemoGuideActivity extends Activity {
private static final String TAG = "flutter_baidumap_plugin";
private IBNRouteGuideManager mRouteGuideManager;
private IBNaviListener.DayNightMode mMode = IBNaviListener.DayNightMode.DAY;
View view;
GuidePop guidePop;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
boolean fullScreen = supportFullScreen();
Bundle params = new Bundle();
params.putBoolean(BNaviCommonParams.ProGuideKey.IS_SUPPORT_FULL_SCREEN, fullScreen);
mRouteGuideManager = BaiduNaviManagerFactory.getRouteGuideManager();
BNGuideConfig config = new BNGuideConfig.Builder()
.params(params)
.build();
view = mRouteGuideManager.onCreate(this, config);
if (view != null) {
setContentView(view);
}
guidePop = new GuidePop(this);
initTTSListener();
routeGuideEvent();
}
// 导航过程事件监听
private void routeGuideEvent() {
BaiduNaviManagerFactory.getRouteGuideManager().setNaviListener(new IBNaviListener() {
@Override
public void onRoadNameUpdate(String name) {
// 弹窗展示
// ControlBoardWindow.getInstance().showControl("当前路名更新——" + name);
guidePop.setdata(name);
}
@Override
public void onRemainInfoUpdate(int remainDistance, int remainTime) {
// 弹窗展示
// ControlBoardWindow.getInstance()
// .showControl("距离目的地的剩余——" + remainDistance + "m " + remainTime + "s");
guidePop.setdata(remainDistance, remainTime);
}
@Override
public void onViaListRemainInfoUpdate(Message msg) {
}
@Override
public void onGuideInfoUpdate(BNaviInfo naviInfo) {
// 弹窗展示
// ControlBoardWindow.getInstance().showControl("诱导信息——" + naviInfo.toString());
guidePop.setdata(naviInfo);
}
@Override
public void onHighWayInfoUpdate(Action action, BNHighwayInfo info) {
// ControlBoardWindow.getInstance()
// .showControl("高速信息——" + action + " " + info.toString());
}
@Override
public void onFastExitWayInfoUpdate(Action action, String name, int dist, String id) {
// ControlBoardWindow.getInstance()
// .showControl("快速路出口信息——" + action + " " + name + " 出口还有" + dist + "米");
}
@Override
public void onEnlargeMapUpdate(Action action, View enlargeMap, String remainDistance,
int progress, String roadName, Bitmap turnIcon) {
// ControlBoardWindow.getInstance().showControl("放大图回调信息——不想写了自己看吧_gb");
}
@Override
public void onDayNightChanged