vue h5 安卓和ios 调用高德地图、百度地图和腾讯地图app

export default {
  name: "navigator",
  data() {
    return {
      actions: [
        { value: "1", name: "高德地图" },
        { value: "2", name: "百度地图" },
        { value: "3", name: "腾讯地图" },
      ],
      lng: "",
      lat: "",
      city: "",
    };
  },
  methods: {
    onSelect(item) {
      // 默认情况下点击选项时不会自动收起
      // 可以通过 close-on-click-action 属性开启自动收起

      /* Start  判断手机是IOS还是安卓 */
      let u = navigator.userAgent;
      //判断是否安卓
      let isAndroid = u.indexOf("Android") > -1 || u.indexOf("Linux") > -1;
      // 判断是否IOS
      let isIOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/);
      //判断是否点击高德地图
      if (item.value == 1) {
        //判断是否是安卓手机
        if (isAndroid) {
          let queryStr = `?sourceApplication=msite&lat=${this.lat}&lon=${this.lng}&dev=1&style=2`;
          window.location.href = `androidamap://navi${queryStr}`;
        } else if (isIOS) {
          let queryStr = `?sourceApplication=msite&lat=${this.lat}&lon=${this.lng}&dev=1&style=2`;
          window.location.href = `iosamap://viewMap${queryStr}`;
        }
        //百度地图
      } else if (item.value == 2) {
        if (isAndroid) {
          let queryStr = `?region=${this.city}&destination=${this.lat},${this.lng}&mode=driving&src=andr.baidu.openAPIdemo`;
          window.location.href = `bdapp://map/direction${queryStr}`;
        } else if (isIOS) {
          let queryStr = `?region=${this.city}&destination=${this.lat},${this.lng}&mode=driving&src=ios.baidu.openAPIdemo`;
          window.location.href = `baidumap://map/direction${queryStr}`;
        }
        //腾讯地图
      } else if (item.value == 3) {
        let queryStr = `?type=drive&fromcoord=CurrentLocation&to=${this.title}&tocoord=${this.lat},${this.lng}&referer=BY7BZ-6YSK7-UMCXU-PAXYI-5NQVT-OWFCL`;
        // 安卓ios通用
        window.location.href = `qqmap://map/routeplan${queryStr}`;
      }
    },
  },
};
  • 7
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值