Vue手机定位

//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;
      }
    }

猜你喜欢

转载自www.cnblogs.com/shenbo666/p/13183024.html
今日推荐