计算地图上2个起点终点的夹角

  1. 确定起点(武汉)坐标,地址解析或者坐标拾取,这里演示使用百度的坐标拾取系统

    1571045803(1).jpg

  2. 确定终点(北京)坐标

    1571045719(1).jpg

  3. 调用函数,获取武汉到北京的角度(以武汉的左侧纬线为0度线)

    echo getJd('114.302378,30.635141','116.399669,39.908958');

    //返回经纬度偏移量

    function getJd($lnglat1,$lnglat2){

        $k1 = explode(',',$lnglat2)[0]-explode(',',$lnglat1)[0];   //经度差

        $k2 = explode(',',$lnglat2)[1]-explode(',',$lnglat1)[1];   //纬度差

        if( 0 == $k1){  //经度重合

            if($k2>0){  //纬度为正

                $angle = 90;

            }

            else if( $k2<0){

                $angle = 270;

            }

            else if( $k2 == 0){

                $angle = 0;

            }

        }else if( 0 == $k2){

            if($k1>0){

                $angle = 180;

            }

            else if( $k1<0){

                $angle = 0;

            }

        }else{

            $k=$k2/$k1;

            if($k2>0){

                if($k1>0){

                    $angle = sprintf ("%.2f",180*atan($k)/M_PI);

                    $angle = 180 - $angle;  //东偏北 $angle 度方向   这里相当于把武汉的左侧的纬线作为0度线,右侧纬线作为180度线

                }else if($k1<0){

                    $angle = sprintf ("%.2f",180*atan(-$k)/M_PI);  //西偏北 $angle 度方向

                }

            }else if($k2<0){

                if($k1<0){

                    $angle = sprintf ("%.2f",180*atan($k)/M_PI);

                    $angle = 360 - $angle;   //西偏南 $angle 度方向

                }

                else if($k1>0){

                    $angle = sprintf ("%.2f",180*atan($k)/M_PI);

                    $angle = 180 - $angle;   //东偏南 $angle 度方向

                }

            }

        }

        return $angle;

    }

    1571045998(1).jpg

  4. 调用函数,获取合肥到太原的角度(以合肥的左侧纬线为0度线)

    1571046512(1).jpg

  5. 角度互减取绝对值,结果就是两条线路的夹角

    echo abs(66.02-102.49);

发表评论

  1. <a href="https://www.ekffo150.com/" target="_blank">??????</a> <a href="https://www.ekffo150.com/yes" target="_blank">?????</a> <a href="https://www.ekffo150.com/first" target="_blank">??????</a> <a href="https://www.ekffo150.com/theking" target="_blank">?????</a> <a href="https://www.ekffo150.com/merit" target="_blank">??????</a> <a h

  2. https://www.ekffo150.com/theking https://www.ekffo150.com/merit https://www.ekffo150.com/yes https://www.ekffo150.com/first https://www.ekffo150.com/sands https://www.ekffo150.com/joy https://www.ekffo150.com/royal https://www.ekffo150.com/starclub https://www.ekffo150.com/asian https://www.ekffo150.com/superman https://www.ekffo150.com/gatsby https://www.ekffo150.com/33casino https://www.ekffo150.com/ondasino https://www.ekffo150.com https://www.ajp4949.com/theking https://www.ajp4949.com/me