uniapp 地图跳转到第三方导航软件 直接打包成apk

javascript 复制代码
// 判断是否存在导航软件
      judgeHasExistNavignation() {
        let navAppParam = [{
            pname: 'com.baidu.BaiduMap',
            action: 'baidumap://'
          }, // 百度
          {
            pname: 'com.autonavi.minimap',
            action: 'iosamap://'
          }, // 高德
          {
            pname: 'com.tencent.map',
            action: 'tencentmap://'
          }, // 腾讯
        ];
        return navAppParam.some(param => {
          return plus.runtime.isApplicationExist(param);
        })
      },
      // 获取用户当前定位
      getPosition() {
        let that = this;
        return new Promise(resolve => {
          uni.getLocation({
            type: 'gcj02',
            geocode: true, //设置该参数为true可直接获取经纬度及城市信息
            success: function(res) {
              let {
                latitude,
                longitude
              } = res
              that.curSysPosition.latitude = latitude;
              that.curSysPosition.longitude = longitude;
              resolve();
            }
          });
        })
      },
      //  打开第三方地图  info对象是目的地的经纬度数据
      // this.info:{
      //   x:
      //   y:
      // }
      async handleOpenNavigation() {
        const lat = this.info.y; //纬度
        const lng = this.info.x; //经度
        const address = '目的地';
        if (!this.judgeHasExistNavignation()) {
          return this.$showToast("该设备上不存在第三方导航APP");
        }
        await this.getPosition();
        let {
          latitude,
          longitude
        } = this.curSysPosition;
        let tLngLat = new plus.maps.Point(lng, lat); // 目的地
        let oLngLat = new plus.maps.Point(longitude, latitude); // 起始地
        plus.maps.openSysMap(tLngLat, address, oLngLat);
      },
      // 地图导航
      toNearbyStore() {
        var url = '';
        const address = '去到这里';
        //地址
        const latitude = this.info.y; //纬度
        const longitude = this.info.x; //精度
        url = 'geo:' + latitude + ',' + longitude + '?q=' + encodeURIComponent(address);
        if (uni.getSystemInfoSync().platform == 'android') {
          plus.runtime.openURL(url);
        } else {
          plus.nativeUI.actionSheet({
            title: "选择地图应用",
            cancel: "取消",
            buttons: [{
              title: "Apple地图"
            }, {
              title: "百度地图"
            }, {
              title: "高德地图"
            }, {
              title: "google地图"
            }]
          }, function(e) {
            console.log("e.index: " + e.index);
            switch (e.index) {
              case 1:
                url =
                  `http://maps.apple.com/?q=${encodeURIComponent(address)}&ll=${latitude},${longitude}&spn=0.008766,0.019441`
                break;
              case 2:
                url = `baidumap://map/marker?location=${latitude},${longitude}&title=DCloud&src=Hello%20uni-app`;
                break;
              case 3:
                url =
                  `iosamap://viewMap?sourceApplication=Hello%20uni-app&poiname=DCloud&lat=${latitude}&lon=${longitude}&dev=0`;
                break;
              case 4:
                url = `comgooglemaps://?q=${encodeURIComponent(address)}&center=${latitude},${longitude}`;
                break;
                plus.runtime.openURL(url, function(e) {
                  plus.nativeUI.alert("未安装此地图");
                });
            }
          })
        }
      },
相关推荐
LXA080930 分钟前
UniApp 小程序中使用地图组件
小程序·uni-app·notepad++
QuantumLeap丶3 小时前
《uni-app跨平台开发完全指南》- 07 - 数据绑定与事件处理
vue.js·ios·uni-app
2501_915909067 小时前
Flutter 应用怎么加固,多工具组合的工程化实战(Flutter 加固/Dart 混淆/IPA 成品加固/Ipa Guard + CI)
android·flutter·ios·ci/cd·小程序·uni-app·iphone
xiaaaa.z9 小时前
macos HbuildX 使用cli脚本创建uniapp 运行时报错“cli项目运行依赖本地的Nodejs环境,请先安装并配置到系统环境变量后重试。”
macos·uni-app
2501_9159090610 小时前
深入理解HTTPS和HTTP的区别、工作原理及安全重要性
安全·http·ios·小程序·https·uni-app·iphone
Q_Q5110082851 天前
python+uniapp基于微信小程序的垃圾分类信息系统
spring boot·python·微信小程序·django·flask·uni-app·node.js
你的眼睛會笑1 天前
uniapp 鸿蒙元服务 真机调试流程指南
华为·uni-app·harmonyos
2501_915921431 天前
查看iOS App实时日志的正确方式,多工具协同打造高效调试与问题定位体系(2025最新指南)
android·ios·小程序·https·uni-app·iphone·webview
雯0609~1 天前
uni-app:实现快递的节点功能
uni-app
前端小菜鸟也有人起1 天前
uniapp集成爱山东获取用户信息
uni-app