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