根据经纬度计算距离

主要参考以下两篇文章,插眼以保存



(8条消息) 根据两点经纬度坐标计算距离_OSKernelLAB(gatieme)-CSDN博客_根据两点经纬度坐标计算距离


(8条消息) 根据经纬度计算两地距离_weixin_34218890的博客-CSDN博客

computeDistance() {
				var that = this
				// 计算纬度差
				var lat1 = that.latitude * Math.PI / 180.0
				var lat2 = that.childLatitude * Math.PI / 180.0
				var latdistinction = Math.abs(lat1 - lat2)

				// 计算经度差
				var long1 = that.longitude * Math.PI / 180.0
				var long2 = that.childLongitude * Math.PI / 180.0
				var longdistinction = Math.abs(long1 - long2)

				//计算两点之间的实际距离(经过我的查询这个公式叫做:Haversine公式)
				var s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(latdistinction / 2), 2) + Math.cos(lat1) * Math.cos(
					lat2) * Math.pow(Math.sin(longdistinction / 2), 2)));
				s = s * 6378.137;
				s = Math.round(s * 10000) / 10000;
				//保留最后两位小数
				s = s.toString();
				s = s.substring(0, s.indexOf('.') + 2);
				console.log(s)
				that.distance = s
				//提醒一下,这里的获取的距离,也就是s的单位是Km

				// 判断方向
				if (that.childLatitude > that.latitude) {
					that.north = true
				} else {
					that.north = false
				}
				if (that.childLongitude > that.childLongitude) {
					that.east = true
				} else {
					that.east = false
				}
			},

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值