更新记录
1.0.0(2025-06-18)
1.0版本,支持步行、骑行、驾车三种方式,支持传入店铺和订单信息
平台兼容性
uni-app(4.44)
Vue2 | Vue3 | Chrome | Safari | app-vue | app-nvue | Android | iOS | 鸿蒙 |
---|---|---|---|---|---|---|---|---|
√ | √ | - | - | - | - | 8.0 | - | - |
微信小程序 | 支付宝小程序 | 抖音小程序 | 百度小程序 | 快手小程序 | 京东小程序 | 鸿蒙元服务 | QQ小程序 | 飞书小程序 | 快应用-华为 | 快应用-联盟 |
---|---|---|---|---|---|---|---|---|---|---|
- | - | - | - | - | - | - | - | - | - | - |
outsource-amap-navi
高德地图导航插件 - UniApp原生插件
简介
本插件基于高德地图SDK开发,为UniApp提供原生导航功能,支持汽车、自行车、步行等多种导航模式。
安装说明
- 将插件放置在项目的
uni_modules
目录下 - 在需要使用的页面中导入插件
import * as nativePlug from "@/uni_modules/outsource-amap-navi"
API 文档
1. requestPermissions() - 权限申请
申请定位等必要权限,建议在使用导航功能前调用。
nativePlug.requestPermissions(res => {
console.log('权限申请结果:', res)
})
2. goNavigation(params) - 开始导航
启动导航功能,支持多种导航模式。
参数说明
参数 | 类型 | 必填 | 说明 |
---|---|---|---|
slatlng | String | 是 | 起点经纬度,格式:"纬度,经度" |
elatlng | String | 是 | 终点经纬度,格式:"纬度,经度" |
tag_name | String | 是 | 目标地点名称 |
tag_addr | String | 是 | 目标地点详细地址 |
type | String | 是 | 地址类型:取货点、送货点、中转点等 |
order_no | String | 是 | 订单号,如:#111 |
jidianqiansongda | String | 是 | 预计送达时间,如:17:44前送达 |
shengyu_time | String | 是 | 剩余时间,如:30分钟 |
phone | String | 是 | 联系电话 |
navType | Number | 是 | 导航类型:1-汽车,2-自行车,3-步行 |
示例代码
nativePlug.goNavigation({
'slatlng': '23.017116,113.738317',
'elatlng': '23.027104,113.739594',
'tag_name': "S-pizza披萨速递(广元店)",
'tag_addr': '育才路恒丰花园56号',
'type': '取',
'order_no': '#111',
'jidianqiansongda': '17:44前送达',
'shengyu_time': '30分钟',
'phone': '10086',
'navType': 2 // 自行车导航
})
3. updateInform(params) - 更新导航信息
动态更新导航过程中的信息,如剩余时间等。
参数说明
参数与 goNavigation
相同。
示例代码
nativePlug.updateInform({
'slatlng': '23.017116,113.738317',
'elatlng': '23.027104,113.739594',
'tag_name': "S-pizza披萨速递(广元店)",
'tag_addr': '育才路恒丰花园56号',
'type': '取',
'order_no': '#111',
'jidianqiansongda': '17:44前送达',
'shengyu_time': '25分钟', // 更新剩余时间
'phone': '10086',
'navType': 1
})
4. stopNavigation() - 停止导航
结束当前导航会话。
nativePlug.stopNavigation(res => {
console.log('导航已停止:', res)
})
完整使用示例
<template>
<view>
<button type="default" @click="requestPermissions">权限申请</button>
<button type="default" @click="goNavigation">进入导航</button>
<button type="default" @click="stopNavigation">关闭导航</button>
</view>
</template>
<script>
import * as nativePlug from "@/uni_modules/outsource-amap-navi"
export default {
data() {
return {
timer: null,
remainingTime: 0
}
},
methods: {
// 申请权限
requestPermissions() {
nativePlug.requestPermissions(res => {
console.log('权限申请结果:', res)
})
},
// 开始导航
goNavigation() {
// 清除之前的定时器
if (this.timer != null) {
clearInterval(this.timer)
this.timer = null
}
// 启动导航
nativePlug.goNavigation({
'slatlng': '23.017116,113.738317',
'elatlng': '23.027104,113.739594',
'tag_name': "S-pizza披萨速递(广元店)",
'tag_addr': '育才路恒丰花园56号',
'type': '取',
'order_no': '#111',
'jidianqiansongda': '17:44前送达',
'shengyu_time': this.remainingTime + '分钟',
'phone': '10086',
'navType': 2 // 自行车导航
})
// 定时更新信息
this.timer = setInterval(() => {
this.remainingTime += 1
nativePlug.updateInform({
'slatlng': '23.017116,113.738317',
'elatlng': '23.027104,113.739594',
'tag_name': "S-pizza披萨速递(广元店)",
'tag_addr': '育才路恒丰花园56号',
'type': '取',
'order_no': '#111',
'jidianqiansongda': '17:44前送达',
'shengyu_time': this.remainingTime + '分钟',
'phone': '10086',
'navType': 1
})
}, 2000)
},
// 停止导航
stopNavigation() {
if (this.timer != null) {
clearInterval(this.timer)
this.timer = null
}
nativePlug.stopNavigation(res => {
console.log('导航已停止')
})
}
}
}
</script>
注意事项
- 权限申请:使用导航功能前务必先调用
requestPermissions()
申请必要权限 - 经纬度格式:经纬度参数格式为 "纬度,经度",注意顺序
- 导航类型:navType 参数:1-汽车,2-自行车,3-步行
- 定时器管理:使用定时器更新信息时,记得在适当时机清除定时器
- 资源清理:页面销毁时记得调用
stopNavigation()
停止导航