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("未安装此地图");
                });
            }
          })
        }
      },
相关推荐
万物得其道者成3 小时前
UniApp 多端滑块验证码插件 zxj-slide-verify 实用指南
uni-app
蓝帆傲亦4 小时前
支付宝小程序性能暴增秘籍:UniApp项目极限优化全攻略
小程序·uni-app
2501_9160088914 小时前
深入解析iOS机审4.3原理与混淆实战方法
android·java·开发语言·ios·小程序·uni-app·iphone
QT.qtqtqtqtqt15 小时前
uni-app小程序前端开发笔记(更新中)
前端·笔记·小程序·uni-app
喵喵虫1 天前
uniapp修改封装组件失败 styleIsolation
uni-app
游戏开发爱好者82 天前
日常开发与测试的 App 测试方法、查看设备状态、实时日志、应用数据
android·ios·小程序·https·uni-app·iphone·webview
2501_915106322 天前
app 上架过程,安装包准备、证书与描述文件管理、安装测试、上传
android·ios·小程序·https·uni-app·iphone·webview
2501_915106322 天前
使用 Sniffmaster TCP 抓包和 Wireshark 网络分析
网络协议·tcp/ip·ios·小程序·uni-app·wireshark·iphone
宠友信息2 天前
2025社交+IM及时通讯社区APP仿小红书小程序
java·spring boot·小程序·uni-app·web app
“负拾捌”2 天前
python + uniapp 结合腾讯云实现实时语音识别功能(WebSocket)
python·websocket·微信小程序·uni-app·大模型·腾讯云·语音识别