java map 已知起点与终点的经纬度与第三个点到起点或者终点的距离 得到第三点的经纬度

package com.bmw.biz.util;

import java.util.HashMap;
import java.util.Map;

/**
 * 2020-6-24 hu
 *
 * 已知AB两点经纬度 和C点到A或者B ,的距离 单位m  求c点的经纬度
 */
public class AngleUtil {

        private final static double Rc=6378137;
        private final static double Rj=6356725;
        private double m_RadLo,m_RadLa;
        private double Ec;
        private double Ed;
        public AngleUtil(double longitude,double latitude){
            m_RadLo=longitude*Math.PI/180.;
            m_RadLa=latitude*Math.PI/180.;
            Ec=Rj+(Rc-Rj)*(90.- latitude)/90.;
            Ed=Ec*Math.cos(m_RadLa);
        }

        /**
         * 求B点经纬度
         * @param A 已知点的经纬度,
         * @param distance   AB两地的距离  单位m
         * @param angle  AB连线与正北方向的夹角(0~360)
         * @return  B点的经纬度
         */
        public static Map getMyLatLng(AngleUtil A, double distance, double angle){
            double dx = distance*Math.sin(Math.toRadians(angle));
            double dy= distance*Math.cos(Math.toRadians(angle));
            double bjd=(dx/A.Ed+A.m_RadLo)*180./Math.PI;
            double bwd=(dy/A.Ec+A.m_RadLa)*180./Math.PI;
            HashMap<String, Double> stringDoubleHashMap = new HashMap<>();
            stringDoubleHashMap.put("lng",bjd);
            stringDoubleHashMap.put("lat",bwd);
            return   stringDoubleHashMap ;
        }



        /**
         * 已知两点经纬度求方位角
         */
        public static double getAngle(double lon1, double lat1, double lon2,
                                      double lat2) {
            double fLat = Math.PI * (lat1) / 180.0;
            double fLng = Math.PI * (lon1) / 180.0;
            double tLat = Math.PI * (lat2) / 180.0;
            double tLng = Math.PI * (lon2) / 180.0;

            double 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) {
                return degree;
            } else {
                return 360 + degree;
            }
        }

        public static void main(String args[]){
            //根据两点找到对应的方位角
            double angle = getAngle(114.021778, 22.73101, 114.03353, 22.737715);

            AngleUtil A =new AngleUtil(114.021778,22.73101);
            System.out.println(getMyLatLng( A,1,angle).toString());
        }


}
  • 0
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值