小程序中定位的封装

161 阅读1分钟

export function getLocationWithSetting(){

return new Promise((resolve,reject)=>{

wx.getSetting({

success:async({authSetting})=>{

//授权了

if(authSetting['scope.userLocation']){

resolve(await getLocation())

}

else{

wx.openSetting({

success:async({authSetting})=>{

if(authSetting['scope.userLocaton']){

resolve(await getLocation())

}

else{

wx.showToast({

title:'为了不应向您的使用,请授权获取位置信息'

icon:'none'

})

}

}

})

}

}

})

})

}