You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

61 lines
1.3 KiB

const {
getAddressByLonLat
} = require('../api/api')
/**
*
*
* 获取用户当前地理位置
*
* @param {*} e
*/
function getLocationAddress(e) {
return new Promise(async (resolve, reject) => {
wx.showLoading({
title: '获取定位中',
})
wx.getLocation({
type: 'gcj02',
isHighAccuracy: true,
success(resLocation) {
getAddressByLonLat({
lonLat: resLocation.longitude + "," + resLocation.latitude
}).then((res) => {
wx.hideLoading()
if (res.code == 200) {
var e = {
res, //接口返回信息
resLocation, //经纬度信息
}
resolve(e)
} else {
wx.showToast({
title: '获取定位失败',
icon: 'none'
})
}
})
},
fail(res) {
wx.hideLoading()
wx.showModal({
title: '提示',
content: '请前往设置开启小程序定位授权',
cancelText: "取消",
confirmText: "确定",
success(res) {
if (res.confirm) {
wx.openSetting({
withSubscriptions: true,
})
}
}
})
}
})
})
}
module.exports = {
getLocationAddress
}