package com.bmw.biz.util;
import java.util.HashMap;
import java.util.Map;
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);
}
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());
}
}