输入2点经纬度,安装1公里计算出线路上经纬度

1.根据2点经纬度计算2点距离(单位公里)

  //经度1
       let j1 = 114.3052500
       let startLon = (Math.PI / 180) * j1 ;

      // 纬度1
      let w1 = 30.592760
      let startLan = (Math.PI / 180) * w1;

      for(let i = 0 ;i<10;i++){
        let endLon = this.getCgGrData[i].perj //经度2
        let endtLan = this.getCgGrData[i].perw //纬度2
        let earthR = 6378;
        let distence = Math.acos(Math.sin(startLan) * Math.sin(endtLan)+ Math.cos(startLan) * Math.cos(endtLan) * Math.cos(endLon - startLon)) * earthR;
        distence = parseInt(distence)
        console.log(distence,'1')
        if(distence%2==0){
          distence = distence
        }else{
          distence = distence+1
        }
        this.getCgGrData[i].distence = distence
      }

      console.log(this.getCgGrData,'距离结果')

2.根据距离计算出路线点 代码示例是计算出抛物线

  for(let i = 0;i<10;i++){
        let index = i
        let Gldistence = this.getCgGrData[i].distence
        let GLfLat = 30.592760
        let GLfLng = 114.3052500
        let GLtLng =  ((this.getCgGrData[i].perj)/Math.PI) * 180;
        let GLtLat = ((this.getCgGrData[i].perw)/Math.PI) * 180 ;
        let A = []
        //最高点
        let maxhight = parseInt((Gldistence+1)/2)
        //y=0点
        let minhight = parseInt((Gldistence+1)/2)
        // 常数
        let constant = maxhight*600
        // 系数
        let coefficient = -(constant/(minhight*minhight))
        
        let a = JSON.parse(GLfLat) / 180 * Math.PI
        let b = JSON.parse(GLfLng) / 180 * Math.PI
        A[0] = [b,a]
        let lasttg = JSON.parse(GLtLng) / 180 * Math.PI
        let lasttt = JSON.parse(GLtLat) / 180 * Math.PI
        for(let i = 1;i<Gldistence+1;i++){
            let fLat = Math.PI * (GLfLat) / 180.0;
            let fLng = Math.PI * (GLfLng) / 180.0;
            let tLat = Math.PI * (GLtLat) / 180.0;
            let tLng = Math.PI * (GLtLng) / 180.0;
            let degree = (Math.atan2(Math.sin(tLng - fLng) * Math.cos(tLat), Math.cos(fLat) * Math.sin(tLat) - Math.sin(fLat) * Math.cos(tLat) * Math.cos(tLng - fLng))) * 180.0 / Math.PI;
            if(degree<0){
              degree = 360+degree
            }
            let Rc=6378137
            let Rj=6356725
            let m_RadLo=GLfLng*Math.PI/180.;
            let m_RadLa=GLfLat*Math.PI/180.;
            let Ec=Rj+(Rc-Rj)*(90.- GLfLat)/90.;
            let Ed=Ec*Math.cos(m_RadLa);

            let dx = 1000*Math.sin(degree*(Math.PI/180));
            let dy= 1000*Math.cos(degree*(Math.PI/180));
            let bjd=(dx/Ed+m_RadLo)*180./Math.PI;
            let bwd=(dy/Ec+m_RadLa)*180./Math.PI;
              A[i] = [bwd,bjd]
              GLfLat= bwd
              GLfLng = bjd
              let c = bwd / 180 * Math.PI
              let d = bjd / 180 * Math.PI
              A[i] = [d,c]
          }

        A[Gldistence] = [lasttg,lasttt]
        A = JSON.parse(JSON.stringify(A))
        console.log(A,'距离')

        for(let i = 0;i<Gldistence+1;i++){
          let x 
          if(i<maxhight){
             x = maxhight - i
          }else if(i>maxhight){
             x = i- maxhight
          }
          A[i][2] = coefficient*(x*x) +constant
          A[maxhight][2] = constant
        }
        A[0][2] = 0
        A[Gldistence][2] = 0

        let lestData = JSON.parse(JSON.stringify(this.LocData))

        let len = lestData.length
        for(let i = 0;i<len;i++){
          for(let x = 0;x<A.length;x++){
            lestData[i].positions.push(A[x])
          }
          this._earth.sceneTree.$refs.zhanyi.children[2].children[index].czmObject.data.push(lestData[i])
        }
          this._earth.sceneTree.$refs.zhanyi.children[2].children[index].enabled = true
          this._earth.sceneTree.$refs.zhanyi.children[2].children[index].czmObject.enabled = true
          console.log(this._earth.sceneTree.$refs.zhanyi)
      }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值