主頁 > 知識庫 > Html5內喚醒百度、高德APP的實現(xiàn)示例

Html5內喚醒百度、高德APP的實現(xiàn)示例

熱門標簽:智能手機 檢查注冊表項 網(wǎng)站建設 美圖手機 使用U盤裝系統(tǒng) 阿里云 硅谷的囚徒呼叫中心 百度競價點擊價格的計算公式

前幾天,聯(lián)合黑卡反饋了一個需求,需要在H5中打開百度APP或者是高德APP,于是我在網(wǎng)上查了相關文檔,下面放上鏈接: 1.高德地圖 2.百度地圖

具體思路就是點擊選擇地圖的時候,先去請求APP鏈接,800毫秒后無響應,再跳轉至H5鏈接。這樣的做法有一點不好就是不管跳不跳APP,都會跳到H5的鏈接。有好的想法可以評論一下。

下面放相關代碼:
 

         function  ToggleAppAndH5( AppUrl , AppCallback = () => {}){
             // 先走APP
            const ifr = document.createElement('iframe');
                ifr.src = AppUrl;
                ifr.style.display = 'none';
                document.body.appendChild(ifr);
                setTimeout(function(){
                    document.body.removeChild(ifr);
                }, 3000);
            
                  // 800毫秒后調用H5鏈接
                let timer = setTimeout(function () {
                        clearTimeout(timer);
                        AppCallback();
                }, 800);
        
                window.onblur = function () {
                    clearInterval(timer);
                };
         }

        function Callback(){
           // 這里放相關H5鏈接
           if (mapType === 'baidu') {
              frameDom.attr('src', "http://api.map.baidu.com/direction?origin=latlng:"+  curLat +","+ curLng +"|name:"+ currAddr +"&destination=latlng:"+  elat +","+ elng +"|name:"+ eaddr +"&region="+ cityName +"&mode=driving&output=html&src=com.youbei.chefu");
           } else if (mapType === 'amap') {
              frameDom.attr('src', "https://ditu.amap.com/dir?type=car&from[lnglat]="+ curLng +","+ curLat +"&from[name]="+currAddr+"&to[lnglat]="+ elng +","+ elat +"&to[name]="+eaddr+"&src=com.youbei.chefu");
           }
         }

         const u = navigator.userAgent;
         const isiOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios終端

1. 高德

   // 蘋果和安卓頭部不一樣
   let proto = isiOS ? 'iosamap://path' : 'amapuri://route/plan'  ;

   const AppUrl = proto + "?t= 0&slat="+curLat+"&slon="+curLng+"&sname="+currAddr+"&dlat="+elat+"&dlon="+elng+"&dname="+eaddr+"&src=xxx";

   ToggleAppAndH5(AppUrl,Callback)

2.百度

   // 蘋果和安卓頭部不一樣
   let proto = isiOS ? 'baidumap://'  : 'bdapp://' 

   const AppUrl = proto +  "map/direction?region="+cityName+"&origin=latlng:"+ curLat+","+ curLng +"|name:"+ currAddr +"&destination=latlng:"+ elat +","+ elng +"|name:"+ eaddr +"&coord_type=bd09ll&mode=driving&src=com.youbei.chefu";
   
   ToggleAppAndH5(AppUrl, Callback)

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。

標簽:山南 賀州 煙臺 懷化 湘潭 通遼 湖北 黃山

巨人網(wǎng)絡通訊聲明:本文標題《Html5內喚醒百度、高德APP的實現(xiàn)示例》,本文關鍵詞  ;如發(fā)現(xiàn)本文內容存在版權問題,煩請?zhí)峁┫嚓P信息告之我們,我們將及時溝通與處理。本站內容系統(tǒng)采集于網(wǎng)絡,涉及言論、版權與本站無關。
  • 相關文章
  • 收縮
    • 微信客服
    • 微信二維碼
    • 電話咨詢

    • 400-1100-266