@@ -757,25 +757,28 @@ const openMap = (mapType) => {
757
757
const longitude = position .getLng ()
758
758
const name = searchValue .value
759
759
760
- // 构建各个地图的 URL Scheme
761
760
let url = ' '
761
+ let appName = ' '
762
762
switch (mapType) {
763
763
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 = ' 高德地图'
765
766
break
766
767
case ' baidu' :
767
768
url = ` baidumap://map/direction?destination=${ latitude} ,${ longitude} &destination_name=${ encodeURIComponent (name)} &mode=driving&coord_type=gcj02`
769
+ appName = ' 百度地图'
768
770
break
769
771
case ' tencent' :
770
772
url = ` qqmap://map/routeplan?type=drive&to=${ encodeURIComponent (name)} &tocoord=${ latitude} ,${ longitude} &referer=myapp`
773
+ appName = ' 腾讯地图'
771
774
break
772
775
}
773
776
774
- // 构建网页版备用链接
777
+ // 修改高德地图的网页版备用链接
775
778
let webUrl = ' '
776
779
switch (mapType) {
777
780
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 `
779
782
break
780
783
case ' baidu' :
781
784
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) => {
785
788
break
786
789
}
787
790
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 // 如果页面隐藏了,说明已经成功打开了应用
805
803
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 秒,让用户能看到提示
810
816
811
817
// 关闭选择器
812
818
showMapSelector .value = false
0 commit comments