我正在尝试将此http://www.movable-type.co.uk/scripts/latlong.html中提供的代码段转换为java.但是我没有得到与网站相同的结果.这是我的代码,用于找到两个点之间的中点,其中给出了它们的纬度和经度
midPoint(12.870672,77.658964,12.974831,77.60935);
public static void midPoint(double lat1,double lon1,double lat2,double lon2)
{
double dLon = Math.toRadians(lon2-lon1);
double Bx = Math.cos(lat2) * Math.cos(dLon);
double By = Math.cos(lat2) * Math.sin(dLon);
double lat3 = Math.atan2(Math.sin(lat1)+Math.sin(lat2),Math.sqrt( (Math.cos(lat1)+Bx)*(Math.cos(lat1)+Bx) + By*By) );
double lon3 = lon1 + Math.atan2(By, Math.cos(lat1) + Bx);
System.out.print(lat3 +" " + lon3 );
}
Run Code Online (Sandbox Code Playgroud)
我不确定dLon是否正确.所以请帮助我们弄明白.PSI需要找到中点的纬度和经度
我一直在使用Moveable-Type网站来帮助我进行一些Geocoordinate计算并且它非常有用,但是,我在计算两个坐标之间的中点时遇到了一个错误.我的结果接近预期,但不够接近:
posA = {47.64570362, -122.14073746}
posB = {47.64316917, -122.14032175}
Run Code Online (Sandbox Code Playgroud)
预期结果(取自可移动型计算器)= 47°38'40"N,122°08'26"W = {47.644444, -122.140556}我的结果:{49.6054801645915, -122.14052959995759}
这是我的代码:
private Geocoordinate MidPoint(Geocoordinate posA, Geocoordinate posB)
{
Geocoordinate midPoint = new Geocoordinate();
double dLon = DegreesToRadians(posB.Longitude - posA.Longitude);
double Bx = Math.Cos(DegreesToRadians(posB.Latitude)) * Math.Cos(dLon);
double By = Math.Cos(DegreesToRadians(posB.Latitude)) * Math.Sin(dLon);
midPoint.Latitude = RadiansToDegrees(Math.Atan2(Math.Sin(DegreesToRadians(posA.Latitude)) + Math.Sin(DegreesToRadians(posB.Latitude)),
Math.Sqrt((Math.Cos(DegreesToRadians(posA.Latitude)) + Bx) * (Math.Cos(DegreesToRadians(posA.Latitude))) + Bx) + By * By));
midPoint.Longitude = posA.Longitude + RadiansToDegrees(Math.Atan2(By, Math.Cos(DegreesToRadians(posA.Latitude)) + Bx));
return midPoint;
}
Run Code Online (Sandbox Code Playgroud)
我有几种私有方法可以在Degrees和Radians之间进行转换.例如
private double DegreeToRadian(double angle) …Run Code Online (Sandbox Code Playgroud)