更新记录

1.0.0(2025-04-07)

新版发布。


平台兼容性

HbuilderX/cli最低兼容版本
4.22

uni-app

Vue2 Vue3
?
app-vue app-nvue app-android app-ios app-harmony
? ? ? ? ?
H5-Safari Android Browser 微信浏览器(Android) QQ浏览器(Android) Chrome IE Edge Firefox PC-Safari
? ? ? ? ? ? ? ? ?
微信小程序 支付宝小程序 百度小程序 字节小程序 QQ小程序 钉钉小程序 快手小程序 飞书小程序 京东小程序
? ? ? ? ? ? ? ? ?
快应用-华为 快应用-联盟
? ?

uni-app x

app-android app-ios
? ?
H5-Safari Android Browser 微信浏览器(Android) QQ浏览器(Android) Chrome IE Edge Firefox PC-Safari
? ? ? ? ? ? ? ? ?

高德一键导航、持续定位UTS插件(鸿蒙版)接口文档

1. 高德导航UTS插件

<script>

    //高德导航UTS插件
    import * as AMapOneNavi from "@/uni_modules/Lizii-AMapOneNavi";

    export default {
    }

</script>

2. 设置高德key(必须)

<script>

    //高德导航UTS插件
    import * as AMapOneNavi from "@/uni_modules/Lizii-AMapOneNavi";

    export default {

        onLoad() {

            //设置高德key
            let apiKey = "xxx";
            AMapOneNavi.setApiKey(apiKey);
        }
    }

</script>

3. 隐私合规检查接口(必须)

<script>

    //高德定位UTS插件
    import * as AMapOneNavi from "@/uni_modules/Lizii-AMapOneNavi";

    export default {

        onLoad() {

            //设置高德key
            let apiKey = "xxx";
            AMapOneNavi.setApiKey(apiKey);

            //隐私合格检查接口
            let isContains = true;
            let isShow = true;
            AMapOneNavi.updatePrivacyShow(isContains, isShow);
            let isAgree = true;
            AMapOneNavi.updatePrivacyAgree(isAgree);
        }
    }

</script>

4. 检查定位服务是否打开

//检查定位服务是否打开
var enable = AMapOneNavi.locationServicesEnabled();//true:定位服务打开 false:定位服务关闭

5. 进入打开定位服务界面

//进入打开定位服务界面
AMapOneNavi.openLocationSetting();

6. 检查定位权限

//检查定位权限是否授权,并申请定位权限
AMapOneNavi.checkLocationPermission(function(res){
    console.log(res);
    if (res.result == true) {

    } else {
        //打开app设置界面 设置始终定位权限
        AMapOneNavi.openAppSetting();
    }
});

7. 检查始终允许后台定位权限

//检查始终允许后台定位权限
AMapOneNavi.checkAlwaysLocationPermission(function(res){
    console.log(res);
    if (res.result == true) {

    } else {
        //打开app设置界面 设置始终允许后台定位
        AMapOneNavi.openAppSetting();
    }
});

8. 打开app设置界面

//打开app设置界面
AMapOneNavi.openAppSetting();

9. 获取当前定位

//获取当前定位
AMapOneNavi.getLocation({
    needAddress:true//是否需要解析地址
}, function(res){
    console.log(res);
    if (res.type == "onLocationData") {
        let latitude = res.data.latitude;//纬度
        let longitude = res.data.longitude;//经度
        let altitude = res.data.altitude;//海拔
        let speed = res.data.speed;//速度
        let bearing = res.data.bearing;//方向
        let time = res.data.time;//方向
        //逆地址信息,当needAddress:true返回以下信息
        let address = res.data.address;//地址
        let country = res.data.country;//国家
        let province = res.data.province;//省/直辖市
        let city = res.data.city;//城市
        let cityCode = res.data.cityCode;//城市编码
        let district = res.data.district;//区
        let adCode = res.data.adCode;//区编码
        let street = res.data.street;//街道名称
        let streetNum = res.data.streetNum;//门牌号
        let aoiName = res.data.aoiName;//所属兴趣点名称
        let poiName = res.data.poiName;//兴趣点名称
    } else if (res.type == "onLocationError") {
        let errorCode = res.data.errorCode;//错误码
        let errorInfo = res.data.errorInfo;//错误消息
    }
});

10. 开启持续定位

//开启持续定位
AMapOneNavi.startLocation({
    needAddress:true,//是否需要解析地址
    allowsBackgroundLocationUpdates:true,//是否允许后台定位
    interval:2000,//定位时间间隔 单位是毫秒
    distanceFilter:0//位置报告距离间隔 单位是米
}, function(res){
    console.log(res);
    if (res.type == "onLocationChanged") {
        let latitude = res.data.latitude;//纬度
        let longitude = res.data.longitude;//经度
        let altitude = res.data.altitude;//海拔
        let speed = res.data.speed;//速度
        let bearing = res.data.bearing;//方向
        let time = res.data.time;//方向
        //逆地址信息,当needAddress:true返回以下信息
        let address = res.data.address;//地址
        let country = res.data.country;//国家
        let province = res.data.province;//省/直辖市
        let city = res.data.city;//城市
        let cityCode = res.data.cityCode;//城市编码
        let district = res.data.district;//区
        let adCode = res.data.adCode;//区编码
        let street = res.data.street;//街道名称
        let streetNum = res.data.streetNum;//门牌号
        let aoiName = res.data.aoiName;//所属兴趣点名称
        let poiName = res.data.poiName;//兴趣点名称
    } else if (res.type == "onLocationError") {
        let errorCode = res.data.errorCode;//错误码
        let errorInfo = res.data.errorInfo;//错误消息
    }
});

11. 停止持续定位

//停止持续定位
AMapOneNavi.stopLocation();

12. 开启后台定位任务

startBackgroundLocationTask() {
    if (uni.getSystemInfoSync().platform == 'harmonyos') {
        //开启后台定位任务
        //如需在后台定位(后台定位需后台定位、后台运行权限),则要在应用切入后台前调用开启后台定位任务,
        AMapOneNavi.startContinuousTask();
    }
}

13. 停止后台定位任务

stopBackgroundLocationTask() {
    if (uni.getSystemInfoSync().platform == 'harmonyos') {
        //停止后台定位任务
        //回到前台可以停止后台任务
        AMapOneNavi.stopContinuousTask();
    }
}

14. 打开一键导航组件

//开始导航
let carInfo = {
    carNumber:"京A12225",//车牌号
    carType:1,//设置车辆类型 0-燃油客车,1-燃油货车,2-纯电动客车,3-纯电动货车,4-插电式混动汽车,5-插电式混动货车,11-摩托车
    //motorcycleCC:7,//设置摩托车排量(cc)
    restriction:true,//设置是否躲避车辆限行。
    //vehicleAxis:2,//设置货车的轴数,carType = 1时候生效,取值[0-255],默认为2
    vehicleHeight:3.9,//设置货车的高度,单位:米,carType = 1时候生效,取值[0-25.5] 如:1.8,1.5等等。
    vehicleLength:15,//设置货车的最大长度,单位:米,carType = 1时候生效,取值[0-25] 如:1.8,1.5等等,默认6米
    vehicleLoad:100,//设置货车的总重,即车重+核定载重,单位:吨,carType = 1时候生效,取值[0-6553.5]
    vehicleLoadSwitch:false,//设置货车重量是否参与算路
    vehicleSize:4,//设置货车的大小,1-微型货车 2-轻型/小型货车 3-中型货车 4-重型货车 默认为2
    vehicleWeight:45,//设置货车的核定载重,单位:吨,carType = 1时候生效,取值[0-6553.5]
    vehicleWidth:2.5//设置货车的最大宽度,单位:米,carType = 1时候生效,取值[0-25.5] 如:1.8,1.5等等。默认2.5米
};//设置车辆信息,进行尾号限行与货车导航
AMapOneNavi.showRoute({
    start:{
        coordinate:{
            latitude:29.72097552154459,
            longitude:106.62744411176179
        },
        name:"渝北区渝航路一巷31号"//,
        //poiId:null//B000A8UIN8"
    },//起点,不设置当前位置做为起点
    wayPoints:[
        {
            coordinate:{
                latitude:29.68751708984375,
                longitude:106.5243967013889
            },
            name:"渝北区"//,
            //poiId:null//"B000A28DAE"
        }
    ],//途径点
    end:{
        coordinate:{
            latitude:29.72097552154459,
            longitude:106.62744411176179
        },
        name:"渝北区渝航路一巷31号"//,
        //poiId:null//B000A8UIN8"
    },//终点,
    pageType:0,//页面类型,1:进入导航页面, 2:进入路线页面 
    //carInfo:carInfo,//设置车辆信息,进行尾号限行与货车导航
    naviMode:1, //1-实时导航 2-模拟导航
    //needCalculateRouteWhenPresent:true,//启动组件进行直接导航时,设置是否进行算路,true : 算路,false : 不会算路。默认为true。
    //needDestroyDriveManagerInstanceWhenNaviExit:true,//退出导航组件是否销毁导航实例,true-退出导航页时停止导航,退出组件时销毁导航 false-退出组件不会销毁导航;当使用组件直接导航时,退出导航页也不会停止导航
    //routeStrategy:10, //设置组件规划路线的策略,默认为速度优先+躲避拥堵+距离较短,参考https://a.amap.com/lbs/static/unzip/Android_Navi_Doc/com/amap/api/navi/enums/PathPlanningStrategy.html
    useInnerVoice:true//是否使用内部语音播报 默认值改为true
}, function(res) {
    console.log(res);
    //回调处理
    let type = res.type;
    let data = res.data;
    if (type == "onArriveDestination") {
        //到达目的地后回调函数。
        var isEmulaterNavi = data; //true代表是模拟导航到达目的地,false代表实时导航到达目的地
        AMapOneNavi.exitRoute();
    } else if (type == "onArrivedWayPoint") {
        //驾车路径导航到达某个途经点的回调函数
        var wayID = data; //到达途径点的编号,标号从0开始,依次累加。
    } else if (type == "onCalculateRouteFailure") {
        //驾车路径规划失败后的回调函数
        var errorInfo = data; //errorInfo-参见PathPlanningErrCode: https://a.amap.com/lbs/static/unzip/Android_Navi_Doc/index.html
    } else if (type == "onCalculateRouteSuccess") {
        //路线规划成功回调
        var ids = data; //路线索引id数组,第一条为12,第二条为13,第三条为14 
    } else if (type == "onExitPage") {
        //退出组件或退出组件导航的回调函数
        var pageType = data;  //1:退出导航页面,2:退出组件页面(包含路径规划、搜索和导航)
    } else if (type == "onGetNavigationText") {
        //导航播报信息回调函数
        var text = data;  //播报文字
    } else if (type == "onInitNaviFailure") {
        //导航初始化失败时的回调函数
    } else if (type == "onLocationChange") {
        //当GPS位置有更新时的回调函数
        var location = data; //当前位置的定位信息,字段参考https://a.amap.com/lbs/static/unzip/Android_Navi_Doc/index.html
    } else if (type == "onStartNavi") {
        //启动导航后的回调函数
        var type = data;//1:实时导航 2:模拟导航 
    }
});

15. 退出导航组件

//到底目的地回调里面,退出导航组件
AMapOneNavi.exitRoute();

隐私、权限声明

1. 本插件需要申请的系统权限列表:

定位权限

2. 本插件采集的数据、发送的服务器地址、以及数据用途说明:

插件自身不采集任何数据,插件使用的高德地图导航 SDK采集数据请参考其官方说明:https://lbs.amap.com

3. 本插件是否包含广告,如包含需详细说明广告表达方式、展示频率:

暂无用户评论。

使用中有什么不明白的地方,就向插件作者提问吧~ 我要提问