Skip to content

Commit b685bb1

Browse files
author
liuhan
committed
修改高德地图导航
1 parent df61d11 commit b685bb1

File tree

1 file changed

+31
-25
lines changed

1 file changed

+31
-25
lines changed

src/views/amap/index.vue

+31-25
Original file line numberDiff line numberDiff line change
@@ -757,25 +757,28 @@ const openMap = (mapType) => {
757757
const longitude = position.getLng()
758758
const name = searchValue.value
759759
760-
// 构建各个地图的 URL Scheme
761760
let url = ''
761+
let appName = ''
762762
switch (mapType) {
763763
case 'gaode':
764-
url = `androidamap://navi?sourceApplication=appname&poiname=${encodeURIComponent(name)}&lat=${latitude}&lon=${longitude}&dev=0&style=2`
764+
url = `androidamap://route/plan/?dlat=${latitude}&dlon=${longitude}&dname=${encodeURIComponent(name)}&dev=0&t=0`
765+
appName = '高德地图'
765766
break
766767
case 'baidu':
767768
url = `baidumap://map/direction?destination=${latitude},${longitude}&destination_name=${encodeURIComponent(name)}&mode=driving&coord_type=gcj02`
769+
appName = '百度地图'
768770
break
769771
case 'tencent':
770772
url = `qqmap://map/routeplan?type=drive&to=${encodeURIComponent(name)}&tocoord=${latitude},${longitude}&referer=myapp`
773+
appName = '腾讯地图'
771774
break
772775
}
773776
774-
// 构建网页版备用链接
777+
// 修改高德地图的网页版备用链接
775778
let webUrl = ''
776779
switch (mapType) {
777780
case 'gaode':
778-
webUrl = `https://uri.amap.com/navigation?to=${longitude},${latitude},${encodeURIComponent(name)}&mode=car&coordinate=gaode&callnative=1`
781+
webUrl = `https://uri.amap.com/route/plan/?dlat=${latitude}&dlon=${longitude}&dname=${encodeURIComponent(name)}&dev=0&t=0`
779782
break
780783
case 'baidu':
781784
webUrl = `https://api.map.baidu.com/direction?destination=${latitude},${longitude}&destination_name=${encodeURIComponent(name)}&mode=driving&output=html&src=webapp.baidu.openAPIdemo`
@@ -785,28 +788,31 @@ const openMap = (mapType) => {
785788
break
786789
}
787790
788-
// 尝试打开应用
789-
if (isWeixinBrowser()) {
790-
// 在微信中直接使用 URL Scheme
791-
window.location.href = url
792-
793-
// 如果几秒后还在当前页面,说明没有安装对应的 APP,跳转到网页版
794-
setTimeout(() => {
795-
if (document.hidden) return // 如果页面隐藏了,说明已经成功打开了应用
796-
window.location.href = webUrl
797-
showToast('未安装对应地图APP,已为您跳转到网页版')
798-
}, 2500)
799-
} else {
800-
// 非微信环境使用 window.open
801-
const openApp = window.open(url)
802-
setTimeout(() => {
803-
if (openApp && !openApp.closed) {
804-
openApp.close()
791+
// 先显示提示
792+
showToast(`正在尝试打开${appName},如未安装将跳转至网页版`)
793+
794+
// 延迟一下再尝试打开应用
795+
setTimeout(() => {
796+
if (isWeixinBrowser()) {
797+
// 在微信中直接使用 URL Scheme
798+
window.location.href = url
799+
800+
// 如果几秒后还在当前页面,说明没有安装对应的 APP,跳转到网页版
801+
setTimeout(() => {
802+
if (document.hidden) return // 如果页面隐藏了,说明已经成功打开了应用
805803
window.location.href = webUrl
806-
showToast('未安装对应地图APP,已为您跳转到网页版')
807-
}
808-
}, 2500)
809-
}
804+
}, 2500)
805+
} else {
806+
// 非微信环境使用 window.open
807+
const openApp = window.open(url)
808+
setTimeout(() => {
809+
if (openApp && !openApp.closed) {
810+
openApp.close()
811+
window.location.href = webUrl
812+
}
813+
}, 2500)
814+
}
815+
}, 1500) // 延迟 1.5 秒,让用户能看到提示
810816
811817
// 关闭选择器
812818
showMapSelector.value = false

0 commit comments

Comments
 (0)