calculateDistance() {
const R = 6371; //地球半径
//latitude 纬度
//longitude 经度
const dLat =this.toRadians(this.latitude - this.latitude2);
const dLon =this.toRadians(this.longitude - this.longitude2);
const a =
Math.sin(dLat / 2) * Math.sin(dLat / 2) +
Math.cos(this.toRadians(this.latitude)) *
Math.cos(this.toRadians(this.latitude2)) *
Math.sin(dLon / 2) *
Math.sin(dLon / 2);
const c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
this.distance = R * c
this.$emit("distance", this.distance);
},
toRadians(degrees) {
return degrees * (Math.PI / 180);
},
VUE通过两地经纬度求距离
最新推荐文章于 2024-04-16 15:33:44 发布