wx.getLocation({
type: 'wgs84',
//res.deviceinfo.lat res.deviceinfo.lng 需要进行对比的坐标点
success(loc) {
var rad1 = res.deviceinfo.lat * Math.PI / 180.0;
var rad2 = loc.latitude * Math.PI / 180.0;
var a = rad1 - rad2;
var b = res.deviceinfo.lng * Math.PI / 180.0 - loc.longitude * Math.PI / 180.0;
var r = 6378.137; //地球半径
var distance = r * 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2), 2) + Math.cos(rad1) * Math.cos(rad2) * Math.pow(Math.sin(b / 2), 2)));
// 两点距离
that.setData({
distance: distance
})
}
})
小程序计算俩坐标点(经纬度)之间的距离
最新推荐文章于 2024-06-11 16:21:16 发布