wanmeiyizhan/pages/scanCodeCharge/appNavigation.vue
ylj20011123 c71b240880 update
2025-05-26 11:48:45 +08:00

41 lines
1.1 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<template>
<view>
<!-- 导航容器 -->
<web-view v-if="showWebView" :src="naviUrl"></web-view>
<!-- 触发按钮 -->
<button @click="startNavigation">开始导航</button>
</view>
</template>
<script>
export default {
data() {
return {
showWebView: false,
naviUrl: ''
}
},
methods: {
async startNavigation() {
// 1. 获取当前位置
const position = await this.getCurrentPosition();
// 2. 构建导航URL高德地图Web版
this.naviUrl = `https://uri.amap.com/navigation?from=120.298501,30.41875&to=116.473168,39.993015&mode=car&src=wanmeiyizhan`;
// 3. 显示WebView
this.showWebView = true;
},
getCurrentPosition() {
return new Promise((resolve, reject) => {
uni.getLocation({
type: 'gcj02',
success: (res) => resolve(res),
fail: (err) => reject(err)
});
});
}
}
}
</script>