2013-03-19 115 views
0

我试图实现从这个site功能。从初始位置,方位和距离得到的位置

φ2= ASIN(SIN(φ1)* COS(d/R)+ COS(φ1)* SIN(d/R)* COS(θ))

λ2=λ1+ ATAN2(罪(θ)* SIN(d/R)* COS(φ1),COS(d/R)-sin(φ1)* SIN(φ2))

//import static java.lang.Math.*;  
public static LatLng fromBearingDistance(double lat1, double lon1, double brng, double d) {  
    double R = 6371.0;  
    double lat2 = Math.asin(Math.sin(lat1)*Math.cos(d/R) + 
       Math.cos(lat1)*Math.sin(d/R)*Math.cos(brng)); 
    double lon2 = lon1 + Math.atan2(Math.sin(brng)*Math.sin(d/R)*Math.cos(lat1), 
        Math.cos(d/R)-Math.sin(lat1)*Math.sin(lat2)); 
    return new LatLng(lat2,lon2); 
} 

从我的功能的结果是:0.0905,1.710当它应该是53.188 0.133与呼叫

fromBearingDistance(53.32055555555556f, 1.7297222222222224f, 
     96.02166666666666f, 124.8f); 

这是与样本站点相同的坐标。

这里可能会发生什么? - 代码字面上就像是一样。我改变的唯一的东西是增加双倍的变数。

我用this网站将度数转换为小数。

回答

2

我认为问题的一部分可能是您的纬度,经度和方位值显示为度,而您链接的页面上的公式要求以弧度表示。如果向下滚动页面,页面作者实际上已经提供了计算的JavaScript实现,作为代表位置的LatLon对象的方法。这里的方法似乎与你正在尝试做的事情相匹配。注意他在计算之前所做的第一件事是将所有内容都转换为弧度,而他所做的最后一件事情是转换回度数。

/** 
* Returns the destination point from this point having travelled the given distance 
* (in km) on the given initial bearing (bearing may vary before destination is reached) 
* 
* see http://williams.best.vwh.net/avform.htm#LL 
* 
* @param {Number} brng: Initial bearing in degrees 
* @param {Number} dist: Distance in km 
* @returns {LatLon} Destination point 
*/ 
LatLon.prototype.destinationPoint = function(brng, dist) 
{ 
    dist = typeof(dist)=='number' ? dist : typeof(dist)=='string' && dist.trim()!='' ? +dist : NaN; 
    dist = dist/this._radius; // convert dist to angular distance in radians 
    brng = brng.toRad(); // 
    var lat1 = this._lat.toRad(), lon1 = this._lon.toRad(); 

    var lat2 = Math.asin(Math.sin(lat1)*Math.cos(dist) + 
         Math.cos(lat1)*Math.sin(dist)*Math.cos(brng)); 
    var lon2 = lon1 + Math.atan2(Math.sin(brng)*Math.sin(dist)*Math.cos(lat1), 
           Math.cos(dist)-Math.sin(lat1)*Math.sin(lat2)); 
    lon2 = (lon2+3*Math.PI) % (2*Math.PI) - Math.PI; // normalise to -180..+180º 

    return new LatLon(lat2.toDeg(), lon2.toDeg()); 
} 

java.lang.Math类有自度来回转换成弧度方法,所以它应该是很容易与他们改造你的代码。

+0

非常好,现在工作完美。另外我想我错误地计算了实际数据! – Andrew 2013-03-19 16:28:51

相关问题