【问题标题】:Determinate a Geopoint from another, a distance, and a polar angle从另一个、距离和极角确定一个地理点
【发布时间】:2013-07-09 18:32:01
【问题描述】:

我正在开发一个使用 Geopoints 的 Android 应用程序,我想确定一个 Geopoint 与另一个 Geopoint、距离(任何格式)和极角。例如,我想通过手机中的 GPS 获取我所在位置的东北 100 米(22.5 度)的坐标。

我找到的唯一方法是Location.distanceBetween(...)

【问题讨论】:

    标签: android gps android-maps


    【解决方案1】:

    Android 的实现。此代码非常适合在您的应用程序中进行单元测试:

    public double radiansFromDegrees(double degrees)
    {
        return degrees * (Math.PI/180.0);
    }
    
    public double degreesFromRadians(double radians)
    {
        return radians * (180.0/Math.PI);
    }
    
    public Location locationFromLocation(Location fromLocation, double distance, double bearingDegrees)
    {
        double distanceKm = distance / 1000.0;
        double distanceRadians = distanceKm / 6371.0;
        //6,371 = Earth's radius in km
        double bearingRadians = this.radiansFromDegrees(bearingDegrees);
        double fromLatRadians = this.radiansFromDegrees(fromLocation.getLatitude());
        double fromLonRadians = this.radiansFromDegrees(fromLocation.getLongitude());
    
        double toLatRadians = Math.asin( Math.sin(fromLatRadians) * Math.cos(distanceRadians)
                                   + Math.cos(fromLatRadians) * Math.sin(distanceRadians) * Math.cos(bearingRadians) );
    
        double toLonRadians = fromLonRadians + Math.atan2(Math.sin(bearingRadians)
                                                     * Math.sin(distanceRadians) * Math.cos(fromLatRadians), Math.cos(distanceRadians)
                                                     - Math.sin(fromLatRadians) * Math.sin(toLatRadians));
    
        // adjust toLonRadians to be in the range -180 to +180...
        toLonRadians = ((toLonRadians + 3*Math.PI) % (2*Math.PI) ) - Math.PI;
    
        Location result = new Location(LocationManager.GPS_PROVIDER);
        result.setLatitude(this.degreesFromRadians(toLatRadians));
        result.setLongitude(this.degreesFromRadians(toLonRadians));
        return result;
    }
    

    【讨论】:

      【解决方案2】:

      看看大圆公式:http://en.wikipedia.org/wiki/Great-circle_distance

      这应该会给你一些关于如何计算距离的提示。

      对于给定距离和航向的点,检查http://williams.best.vwh.net/avform.htm#LL 这些公式看起来很复杂,但很容易实现;)

      【讨论】:

      • 我为一个工作项目实现了这个。因此,很抱歉我不能分享代码。
      • 我已经在下面分享了我的代码......我希望这将为更多用户节省一些时间;)
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-04-12
      • 1970-01-01
      • 1970-01-01
      • 2023-04-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多