onShow(e) {
this.isGetLocation();
},
isGetLocation(a="scope.userLocation"){
var _this = this;
uni.getSetting({
success(res) {
if (!res.authSetting[a]) {
_this.getAuthorizeInfo()
}else{
_this.getLocation1()
}
}
});
},
getAuthorizeInfo(a="scope.userLocation"){
var _this = this;
uni.authorize({
scope: a,
success() {
_this.getLocation();
},
fail(){
showModalWithOptional("微信小程序需要您的位置信息,请前往开启", false, (res) => {
if(res.confirm) {
uni.openSetting({});
}
})
}
})
},
showModalWithOptional(text,isCancel,successFunc){
uni.showModal({
showCancel: isCancel,
title: "温馨提示",
content:text,
confirmColor: "#E02020",
success: (res) => {
successFunc(res)
}
});
},
async getLocation1() {
const { latitude,longitude } = await getLocation({ type: 'GCJ-02'})
},
getLocation(object = {}) {
return new Promise((resolve, reject) => {
object.success = (...args) => {
resolve(...args)
};
object.fail = (error) => {
reject({message: '定位失败,请确定手机已开启定位功能'})
};
object.complete = () => {
}
uni.getLocation(object);
})
}