以前写了,后来调用别的插件了。
删了可惜,留在这吧。
//取地理位置存储
getloact(){
let that = this;
// 开启地图服务for 微信
// #ifdef MP-WEIXIN
uni.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为真
uni.getLocation({
type: 'gcj02',
success(res) {
console.log(res);
that.lat = res.latitude;
that.lon = res.longitude;
let location = {
lat: res.latitude,
lon: res.longitude
};
console.log(location);
uni.setStorageSync('location', location);
// that._getNearParking2(res.latitude, res.longitude);
},
})
} else { // scope.userInfo:false
console.log("scope.userInfo:false");
//打开授权设置
uni.openSetting();
}
} else { //scope.userInfo字段不存在
uni.getLocation({
type: 'gcj02',
success(res) {
that.lat = res.latitude;
that.lon = res.longitude;
let location = {
lat: res.latitude,
lon: res.longitude
};
console.log(location);
uni.setStorageSync('location', location);
// that._getNearParking2(res.latitude, res.longitude);
},
})
}
},
});
// #endif
}