【问题标题】:Resulting position from initial position, bearing and distance从初始位置、方位角和距离得出的位置
【发布时间】:2013-03-07 15:09:12
【问题描述】:

我已尝试从这个site 实现该功能。

φ2 = asin( sin(φ1)*cos(d/R) + cos(φ1)*sin(d/R)*cos(θ) )

λ2 = λ1 + atan2( sin(θ)*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.133with 调用时

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

与示例站点的坐标相同。

这里会发生什么? - 代码字面上的意思是一样的。我唯一改变的是 vars 到 doubles。

我使用this 站点将度数转换为十进制数。

【问题讨论】:

    标签: java geolocation coordinates


    【解决方案1】:

    我认为部分问题可能是您的纬度、经度和方位值似乎以度为单位,而您链接的页面上的公式要求它们以弧度为单位。如果您将页面向下滚动到底部,页面作者实际上已经提供了计算的 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 类具有从度数到弧度数来回转换的方法,因此使用它们改进代码应该很容易。

    【讨论】:

    • 很好,现在可以完美运行。另外我认为我计算的实际数据不正确!
    猜你喜欢
    • 2011-02-18
    • 2015-02-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-12-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多