//APP定位
    getAddress() {
      console.log(77777);

      if (navigator.geolocation) {
        navigator.geolocation.getCurrentPosition(
          this.showPosition,
          this.showError
        );
      } else {
        Toast.fail("不支持地理定位");
      }
    },
    showPosition(position) {
      Toast.loading({
        mask: true,
        message: "加载中..."
      });
      let lat = position.coords.latitude; //纬度
      let lng = position.coords.longitude; //经度
      let date = {
        addr: lng + "_" + lat
      };
      // this.addmsg.address = lat;
      this.$http.post("xy/getPos", date).then(res => {
        // console.log(res);
        if (res.status == 1) {
          this.addmsg.address = res.data;
        } else if (res.status == 0) {
          Toast.fail(res.data);
        }
      });
    },
    showError(error) {
      switch (error.code) {
        case error.PERMISSION_DENIED:
          Toast.fail("定位失败,用户拒绝请求地理定位");
          break;
        case error.POSITION_UNAVAILABLE:
          Toast.fail("定位失败,位置信息是不可用");
          break;
        case error.TIMEOUT:
          Toast.fail("定位失败,请求获取用户位置超时");
          break;
        case error.UNKNOWN_ERROR:
          Toast.fail("定位失败,定位系统失效");
          break;
      }
    }

相关文章:

  • 2021-11-30
  • 2022-12-23
  • 2021-11-17
  • 2022-12-23
  • 2021-10-05
  • 2021-08-21
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-09-17
  • 2021-12-12
  • 2022-12-23
  • 2021-10-05
  • 2022-12-23
  • 2021-10-10
相关资源
相似解决方案