sign: function () {
var that = this
const la1 = 31.991362
const lo1 = 118.737908
wx.getLocation({
type: ‘gcj02’,
success: function (res) {
const la2 = res.latitude
const lo2 = res.longitude
var La1 = la1 * Math.PI / 180.0;
var La2 = la2 * Math.PI / 180.0;
var La3 = La1 - La2;
var Lb3 = lo1 * Math.PI / 180.0 - lo2 * Math.PI / 180.0;
var s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(La3 / 2), 2) + Math.cos(La1) * Math.cos(La2) * Math.pow(Math.sin(Lb3 / 2), 2)));
s = s * 6378.137;//地球半径
s = Math.round(s * 10000) / 10000;
if (s > 0.2) {
wx.showToast({
title: ‘距离不够’ + s,
icon: ‘none’
})
console.log(“距离不够” + s)
} else {
wx.showToast({
title: ‘签到成功’,
icon: ‘success’
})
console.log(“sssssssss===” + s)
}
}
})
//判断是否获得了用户地理位置授权
wx.getSetting({
success: function(res){
if (!res.authSetting[‘scope.userLocation’]){
wx.openSetting({
success: function (res) {
if (res.authSetting[“scope.userLocation”]) {
wx.showToast({
title: ‘授权成功’,
icon: ‘success’,
duration: 1000
})
}
}
})
}
}
})
}