ionic1通过高德,百度,腾讯地图进行路线导航

安装插件
cordova plugin add cordova-plugin-device    //获取设备信息
cordova plugin add cordova-plugin-appavailability --save   //检查地图app是否存在
cordova plugin add cordova-plugin-inappbrowser    //使用内置浏览器
cordova plugin add https://github.com/lampaa/com.lampa.startapp.git   //跳转第三方
cordova plugin add https://github.com/hewz/cordova-baidu-location --variable API_KEY="应用秘钥"     //安装百度地图插件
n02tw2VUyodL4lG4ejfVNFGEFZivg1vO

判断机身版本信息,进行判断跳转Android版本还是iOS版本手机应用
      if (device.platform === 'iOS') {
      schemeIntent = "iosamap://"
      } else if (device.platform === 'Android') {
      schemeIntent = 'com.autonavi.minimap';
      // alert("09")
      }
代码设置(Android版本)
 // 设置判断,判断iOS还是Android
      appAvailability.check(schemeIntent, hasAndroidPackage, notAndroidPackage);   //Android                        function hasAndroidPackage() { } // 存在对应APP       
      function hasAndroidPackage() {
      var sApp = startApp.set({  //跳转对应APP 
        "action": "ACTION_VIEW",
        "category": "CATEGORY_DEFAULT",
        "type": "text/css",
        "package": "com.autonavi.minimap",
        "uri": "amapuri://route/plan/?sid=BGVIS1&slat="+jingweiLat+"&slon="+jingweiLong+"&sname=我的位置&did=BGVIS2&dlat="+pointlat+"&dlon="+pointlng+"&dname="+stationAddress+"&dev=0&t=0",   //选择路径规划然后导航的
        "flags": ["FLAG_ACTIVITY_CLEAR_TOP", "FLAG_ACTIVITY_CLEAR_TASK"],
        "intentstart": "startActivity",
      }, { /* extras */
        "EXTRA_STREAM": "extraValue1",
        "extraKey2": "extraValue2"
        });
      sApp.start(function () { //跳转成功  
      }, function (error) { //失败 
        alert(error);
      });
  
      }
      function notAndroidPackage() {  // 不存在对应APP 
      alert('请更换地图APP或下载该地图APP');
      } 
      
  }
代码设置(Ios版本)
注意:此次测试代码中未加入该部分
appAvailability.check(schemeIntent,hasIosPackage,notIosPackage);   //IOS
function hasIosPackage() {  // 存在对应APP  
  var sApp = startApp.set("iosamap://path?sourceApplication=applicationName&sid=BGVIS1&slat=39.92848272&slon=116.39560823&sname=A&did=BGVIS2&dlat=39.98848272&dlon=116.47560823&dname=B&dev=0&t=0");  
   sApp.start(function() {  
     alert("OK");  
  }, function(error) { 
     alert(error);  
   });  
} 
function notIosPackage()() {  // 不存在对应APP 
  alert('请更换地图APP或下载该地图APP');  
} 

参考文档 https://blog.csdn.net/padding_scater/article/details/78997220#commentBox
https://blog.csdn.net/padding_scater/article/details/78997220

百度地图(更换schemeIntent的值以及package和uri地址就可以)

var schemeIntents;   // 地图APP Package Name
        if (device.platform === 'iOS') {
          schemeIntents = 'baidumap://'
        } else if (device.platform === 'Android') {
          schemeIntents = 'com.baidu.BaiduMap';
        }
 appAvailability.check(schemeIntents,hasIosPackages,notIosPackage);   //IOS
        function hasIosPackages() {  // 存在对应APP
          var sApp = startApp.set("baidumap://map/direction?origin="+jingweiLat+","+jingweiLong+"&destination="+name+"&coord_type=bd09ll&mode=driving&src=ios.baidu.openAPIdemo");  
           sApp.start(function() {  
        //      alert("OK");  
          }, function(error) { 
              // alert('未打开百度地图')
           });  
        } 
      appAvailability.check(schemeIntents, hasAndroidPackages, notAndroidPackage);   //Android                        function hasAndroidPackage() {  // 存在对应APP       	
      function hasAndroidPackages() {
        let baiduApp = startApp.set(
        {
        "action":"ACTION_VIEW", 
          "category":"CATEGORY_DEFAULT", 
          "type":"text/css", 
          "package":'com.baidu.BaiduMap', 
          "uri": "baidumap://map/direction?origin="+jingweiLat+","+jingweiLong+"&destination="+name+"&coord_type=bd09ll&mode=driving&src=andr.baidu.openAPIdemo" ,
        //   "uri":"baidumap://map/direction?origin="+jingweiLat+","+jingweiLong+"&destination="+pointlat+","+pointlng+"&coord_type=bd09ll&mode=driving&src=andr.baidu.openAPIdemo",
  // "baidumap://map/direction?region=beijing&origin=39.98871,116.43234&destination=西直门&coord_type=bd09ll&mode=driving&src=andr.baidu.openAPIdemo" 
          "flags":["FLAG_ACTIVITY_CLEAR_TOP","FLAG_ACTIVITY_CLEAR_TASK"], 
          "intentstart":"startActivity", 
          }, { /* extras */ 
          "EXTRA_STREAM":"extraValue1", 
          "extraKey2":"extraValue2" 
          }
          );
          baiduApp.start(function(){
          // alert('baidu ok')
          },function(error){
            // alert('未打开百度地图')
          })
        }
    }

腾讯地图路线导航

var schemeIntentsqq;   // 地图APP Package Name
        if (device.platform === 'iOS') {
          schemeIntentsqq = 'qqmap://'
        } else if (device.platform === 'Android') {
          schemeIntentsqq = 'com.tencent.map';
        }
        appAvailability.check(schemeIntentsqq,hasIosPackageqq,notIosPackage);   //IOS
        function hasIosPackageqq() {  // 存在对应APP  
          var sApp = startApp.set("qqmap://map/routeplan?type=drive&from=我的位置&fromcoord="+jingweiLat+","+jingweiLong+"&to="+name +"&tocoord= " + pointlat + "," + pointlng + "&referer=OB4BZ-D4W3U-B7VVO-4PJWW-6TKDJ-WPB77");  
           sApp.start(function() {  
        //      alert("OK");  
          }, function(error) { 
              // alert('未打开腾讯地图')
           });  
        } 

      appAvailability.check(schemeIntentsqq, hasAndroidPackagesqq, notAndroidPackage);   //Android                        function hasAndroidPackage() {  // 存在对应APP       	

      function hasAndroidPackagesqq() {
        let qqApp = startApp.set(
        {
        "action":"ACTION_VIEW", 
          "category":"CATEGORY_DEFAULT", 
          "type":"text/css", 
          "package":'com.tencent.map', 
          "uri":"qqmap://map/routeplan?type=drive&from=我的位置&fromcoord="+jingweiLat+","+jingweiLong+"&to="+name +"&tocoord= " + pointlat + "," + pointlng + "&referer=OB4BZ-D4W3U-B7VVO-4PJWW-6TKDJ-WPB77",
          "flags":["FLAG_ACTIVITY_CLEAR_TOP","FLAG_ACTIVITY_CLEAR_TASK"], 
          "intentstart":"startActivity", 
          }, { /* extras */ 
          "EXTRA_STREAM":"extraValue1", 
          "extraKey2":"extraValue2" 
          }
          );
          qqApp.start(function(){
          // alert('baidu ok')
          },function(error){
            // alert('未打开腾讯地图')
          })
        }

config配置

//高德地图
<allow-intent href="androidamap://*/*" />  //android
<allow-intent href="iosamap://*/*" /> //ios
//百度地图
<allow-intent href="bdapp://*/*" /> //android
<allow-intent href="baidumap://*/*" /> //ios
腾讯A&I
  <allow-intent href="qqmap://*/*" />

猜你喜欢

转载自blog.csdn.net/weixin_43806483/article/details/84578357