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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM