wx.getLocation({ //自己的经纬度
type: 'wgs84',
success: function(res) {
var latitude = res.latitude; //纬度
var longitude = res.longitude; //经度
}
})
onLoad: function (options) {
this.distance(la1, lo1, la2, lo2) ; //二者之间的距离
// 修改distance这里面的四个参数 la1为a地点的纬度 ,lo1为a地点的纬度 ,la2为b地点的纬度 ,lo2为b地点的纬度
}
distance: function (la1, lo1, la2, lo2) { //计算距离 km
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;
return s
// console.log("计算结果:"+s+"km");
},