微信小程序 功能函数 地图定位相对直线距离

 
GetDistance:function(lat1, lng1, lat2, lng2){
// console.log(lat1)
var radLat1 = lat1 * Math.PI / 180.0;
var radLat2 = lat2 * Math.PI / 180.0;
 
var a = radLat1 - radLat2;
 
var b = lng1 * Math.PI / 180.0 - lng2 * Math.PI / 180.0;
 
var s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2), 2) + Math.cos(radLat1) * Math.cos(radLat2) * Math.pow(Math.sin(b / 2), 2)));
 
s = s * 6378.137;
 
s = Math.round(s * 10000) / 10000;
console.log(s)
return s;
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
let that = this;
let a1,a2,b1,b2;
wx.chooseLocation({
success: function (res) {
a1 = res.latitude;
a2=res.longitude;
wx.chooseLocation({
success: function (res) {
b1 = res.latitude;
b2 = res.longitude;
console.log(a1)
console.log(a2)
console.log(b1)
console.log(b2)
that.GetDistance(a1, a2, b1, b2)
}
})
}
})
// wx.getLocation({
// type: 'wgs84',
// success: function (res) {
// console.log(res.latitude)
// console.log(res.longitude)
// }
// })
 
 
},

转载于:https://www.cnblogs.com/dianzan/p/8319940.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值