当前位置: 代码迷 >> 综合 >> uniapp-获取位置uni.getLocation(OBJECT)
  详细解决方案

uniapp-获取位置uni.getLocation(OBJECT)

热度:5   发布时间:2024-01-26 23:34:09.0
 // 开启地图服务for 微信// #ifdef MP-WEIXINuni.getSetting({success: res => {console.log("res.authSetting",res.authSetting);if (res && res.authSetting && res.authSetting.hasOwnProperty('scope.userLocation')) { //scope.userInfo字段存在if (res.authSetting['scope.userLocation']) { //scope.userInfo:true为真wx.getLocation({type: 'gcj02',success(res) {that.lat = res.latitude;that.lon = res.longitude;let location = {lat: res.latitude,lon: res.longitude};uni.setStorageSync('location', location);that._getNearParking2(res.latitude, res.longitude);},})} else { // scope.userInfo:falseconsole.log("scope.userInfo:false");//打开授权设置wx.openSetting();}} else { //scope.userInfo字段不存在wx.getLocation({type: 'gcj02',success(res) {that.lat = res.latitude;that.lon = res.longitude;let location = {lat: res.latitude,lon: res.longitude};uni.setStorageSync('location', location);that._getNearParking2(res.latitude, res.longitude);},})}},});// #endif

 

  相关解决方案