微信h5 导航,微信导航

在开发微信h5中使用了一次微信内置api 但是需要80端口 最后未采用

 <div class="address" @click.stop="weixin()">
    <div class="address-left">{{ item["地址"] }}</div>
    <div
      class="address-right"
      v-if="item['坐标'] != ''"
      @click="
        goto(item['坐标'].lat, item['坐标'].lng, item['地址'])
      "
    >
      <img src="../assets/images/address.png" alt="" />
    </div>
  </div>
 async weixin() {
      let ua = navigator.userAgent;
      // 判断机型
      if (!!ua.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/)) {
        // IOS系统 JSSDK验证时使用的URL参数
        this.url = window.location.href.split("#")[0];
      } else {
        this.url = window.location.href.split("#")[0];
        // 安卓
      }
      let res = await wx_sign(localStorage.getItem("token"), this.url);
      if (res.data.code != 1) {
        this.$toast.fail("获取地理坐标失败");
      } else {
        // 调用微信sdk配置函数 将后端传参 进行配置
        this.configInfo(res.data.data);
      }
    },
    // 进行微信sdk参数配置
    configInfo(res) {
      this.$wx.config({
        debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
        appId: res.appId, // 必填,公众号的唯一标识
        timestamp: res.timestamp, // 必填,生成签名的时间戳
        nonceStr: res.nonceStr, // 必填,生成签名的随机串
        signature: res.signature, // 必填,签名
        jsApiList: ["apiList", "openLocation"],
        // 必填,需要使用的JS接口列表
      });
      // 处理成功后回调
      this.$wx.ready(function () {
        console.log("处理成功:");
      });
      // 处理失败后回调
      this.$wx.error(function (err) {
        console.log("处理失败:", err);
      });
    },
    // 点击导航按钮  查看位置
    goto(res, rea, address) {
      this.$wx.openLocation({
        latitude: Number(res), // 纬度,浮点数,范围为90 ~ -90
        longitude: Number(rea), // 经度,浮点数,范围为180 ~ -180。
        name: address, // 位置名
        address: address, // 地址详情说明
        scale: 10, // 地图缩放级别,整型值,范围从1~28。默认为最大
        infoUrl: "", // 在查看位置界面底部显示的超链接,可点击跳转
      });
    },

后来直接这样用比调用微信的sdk简单多了(注意 百度、高德的、经纬度不同 需要转换哦!)

 <div class="map-line">
  <a :href="`http://api.map.baidu.com/marker?location=${list.BaiduMap_Y},${list.BaiduMap_X}&title=${list.Name}&content=${list.Address}&output=html`"
      >百度地图</a>
  </div>
  <div>
    <a  :href="`https://uri.amap.com/marker?position=${list.GaodeMap_X},${list.GaodeMap_Y}&name=${list.Name}`"
      >高德地图</a>
  </div>
 <van-popup
      v-model:show="show"
      position="bottom"
      :style="{ height: '7.25rem' }"
      closeable
    >
      <div class="map_pop_cont">
        <div class="map-line">
          <a
            :href="`http://api.map.baidu.com/marker?location=${list.BaiduMap_Y},${list.BaiduMap_X}&title=${list.Name}&content=${list.Address}&output=html`"
            >百度地图</a
          >
        </div>
        <div>
          <a
            :href="`https://uri.amap.com/marker?position=${list.GaodeMap_X},${list.GaodeMap_Y}&name=${list.Name}`"
            >高德地图</a
          >
        </div>
      </div>
    </van-popup>
    
	// 地图弹出层
	const show = ref(false);
	const showPopup = () => {
	  show.value = true;
	};
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值