百度地图---------获取两个坐标之间的点

通过两个坐标,获取这两个坐标点中间的坐标点
// 已知的两个坐标点
  pointArr = [new BMap.Point(113.854687, 22.502549), new BMap.Point(113.8429946899414, 22.499418258666992)];
  // 获取两个坐标点之间的位置
  getMidpoiont() {
    const lngca =
      (Math.max(parseFloat(this.pointArr[0].lng), parseFloat(this.pointArr[1].lng)) -
        Math.min(parseFloat(this.pointArr[0].lng), parseFloat(this.pointArr[1].lng))) /
      2;
    const latca =
      (Math.max(parseFloat(this.pointArr[0].lat), parseFloat(this.pointArr[1].lat)) -
        Math.min(parseFloat(this.pointArr[0].lat), parseFloat(this.pointArr[1].lat))) /
      2;
    const lngcenter = Math.min(parseFloat(this.pointArr[0].lng), parseFloat(this.pointArr[1].lng)) + lngca;
    const latcenter = Math.min(parseFloat(this.pointArr[0].lat), parseFloat(this.pointArr[1].lat)) + latca;
    const pointcenter = new BMap.Point(lngcenter, latcenter);
    return pointcenter;
  }
通过两个坐标获取两个坐标连线的角度
getAngle() {
    // 船尾 116.329898,39.964613
    const next = {
      point: {
        latitude: 116.329898,
        longitude: 39.964613,
      },
    };
    // 船头 116.549516,39.930539
    const n = {
      point: {
        latitude: 116.549516,
        longitude: 39.930539,
      },
    };
    let ret;
    const w1 = (n.point.latitude / 180) * Math.PI;
    const j1 = (n.point.longitude / 180) * Math.PI;
    const w2 = (next.point.latitude / 180) * Math.PI;
    const j2 = (next.point.longitude / 180) * Math.PI;
    ret = 4 * Math.pow(Math.sin((w1 - w2) / 2), 2) - Math.pow(Math.sin((j1 - j2) / 2) * (Math.cos(w1) - Math.cos(w2)), 2);
    ret = Math.sqrt(ret);
    const temp = Math.sin((j1 - j2) / 2) * (Math.cos(w1) + Math.cos(w2));
    ret = ret / temp;
    ret = (Math.atan(ret) / Math.PI) * 180;
    ret += 90;
    if (j1 - j2 < 0) {
      if (w1 - w2 < 0) {
        // tslint:disable-next-line:no-unused-expression
        ret;
      } else {
        ret = -ret + 180;
      }
    } else {
      if (w1 - w2 < 0) {
        ret = 180 + ret;
      } else {
        ret = -ret;
      }
    }
    return 180 - ret;
  }
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值