Java 的纬度/经度和距离问题

发布于 2024-12-09 00:01:39 字数 1687 浏览 2 评论 0原文

我试图让一部分代码正常工作(类似于我下面的代码),以便 OBJECT_LOC 和 CONVERTED_LOC 完全相同。我认为代码与我正在做的事情非常简单,但由于某种原因它们的结果并不相同?我做错了什么? (您可以在下面看到输出)。

import com.bbn.openmap.LatLonPoint;
import com.bbn.openmap.proj.Length;
import com.bbn.openmap.proj.coords.DMSLatLonPoint;

public class Test {

       /**
        * @param args
        */
       public static void main(String[] args) {

               // 45:20:00.0N/24:00:00.0E
               LatLonPoint BASE_LOC = new DMSLatLonPoint(false, 45, 20, 00.0f, false,
                               24, 00, 00.0f).getLatLonPoint();

               System.out.println("BASE_LOC: " + BASE_LOC);

               LatLonPoint OBJECT_LOC = new LatLonPoint(52.749355, 26.346556);

               System.out.println("OBJECT_LOC: " + OBJECT_LOC);

               float distanceX = BASE_LOC.distance(new LatLonPoint(BASE_LOC
                               .getLatitude(), OBJECT_LOC.getLongitude()));

               float distanceY = BASE_LOC.distance(new LatLonPoint(OBJECT_LOC
                               .getLatitude(), BASE_LOC.getLongitude()));


               LatLonPoint CONVERTED_POINT = new LatLonPoint(BASE_LOC.getLatitude()
                               + Length.DECIMAL_DEGREE.fromRadians(distanceY),
                               BASE_LOC.getLongitude()
                                               + Length.DECIMAL_DEGREE.fromRadians(distanceX));

               System.out.println("CONVERTED_POINT " + CONVERTED_POINT);

       }
}

输出:

BASE_LOC: LatLonPoint[lat=45.333332,lon=24.0]
OBJECT_LOC: LatLonPoint[lat=52.749355,lon=26.346556]
CONVERTED_POINT LatLonPoint[lat=52.749355,lon=25.649527]

I am trying to get a portion of code to work (similar to what I have below), so that OBJECT_LOC and CONVERTED_LOC are exactly the same. I thought the code was pretty straightforward with what I was doing, but for some reason they don't come out equal? What am I doing wrong? (You can see output below).

import com.bbn.openmap.LatLonPoint;
import com.bbn.openmap.proj.Length;
import com.bbn.openmap.proj.coords.DMSLatLonPoint;

public class Test {

       /**
        * @param args
        */
       public static void main(String[] args) {

               // 45:20:00.0N/24:00:00.0E
               LatLonPoint BASE_LOC = new DMSLatLonPoint(false, 45, 20, 00.0f, false,
                               24, 00, 00.0f).getLatLonPoint();

               System.out.println("BASE_LOC: " + BASE_LOC);

               LatLonPoint OBJECT_LOC = new LatLonPoint(52.749355, 26.346556);

               System.out.println("OBJECT_LOC: " + OBJECT_LOC);

               float distanceX = BASE_LOC.distance(new LatLonPoint(BASE_LOC
                               .getLatitude(), OBJECT_LOC.getLongitude()));

               float distanceY = BASE_LOC.distance(new LatLonPoint(OBJECT_LOC
                               .getLatitude(), BASE_LOC.getLongitude()));


               LatLonPoint CONVERTED_POINT = new LatLonPoint(BASE_LOC.getLatitude()
                               + Length.DECIMAL_DEGREE.fromRadians(distanceY),
                               BASE_LOC.getLongitude()
                                               + Length.DECIMAL_DEGREE.fromRadians(distanceX));

               System.out.println("CONVERTED_POINT " + CONVERTED_POINT);

       }
}

Output:

BASE_LOC: LatLonPoint[lat=45.333332,lon=24.0]
OBJECT_LOC: LatLonPoint[lat=52.749355,lon=26.346556]
CONVERTED_POINT LatLonPoint[lat=52.749355,lon=25.649527]

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

猛虎独行 2024-12-16 00:01:39

在查看了 API 文档和一些地理文献之后,您发现第二点的方法似乎有缺陷。正确的方法是使用距离和方位角(方位角)。以下是更正后的代码:

import com.bbn.openmap.LatLonPoint;
import com.bbn.openmap.proj.coords.DMSLatLonPoint;

public class TestProgram {

   /**
    * @param args
    */
   public static void main(String[] args) {

           // 45:20:00.0N/24:00:00.0E
           LatLonPoint BASE_LOC = new DMSLatLonPoint(false, 45, 20, 00.0f, false, 24, 00, 00.0f).getLatLonPoint();
           System.out.println("BASE_LOC: " + BASE_LOC);

           LatLonPoint OBJECT_LOC = new LatLonPoint(52.749355, 26.0);
           System.out.println("OBJECT_LOC: " + OBJECT_LOC);

           float distance = BASE_LOC.distance(OBJECT_LOC);
           float az = BASE_LOC.azimuth(OBJECT_LOC);

           LatLonPoint CONVERTED_POINT = BASE_LOC.getPoint(distance, az);

           System.out.println("CONVERTED_POINT " + CONVERTED_POINT);

   }

}

此处提供了一些信息 - http://www. move-type.co.uk/scripts/latlong.html

After looking at the API docs and some literature on geography it looks like your method of finding out the second point is flawed. The right way to do it is using the distance and the bearing(azimuth). Following is the corrected code:

import com.bbn.openmap.LatLonPoint;
import com.bbn.openmap.proj.coords.DMSLatLonPoint;

public class TestProgram {

   /**
    * @param args
    */
   public static void main(String[] args) {

           // 45:20:00.0N/24:00:00.0E
           LatLonPoint BASE_LOC = new DMSLatLonPoint(false, 45, 20, 00.0f, false, 24, 00, 00.0f).getLatLonPoint();
           System.out.println("BASE_LOC: " + BASE_LOC);

           LatLonPoint OBJECT_LOC = new LatLonPoint(52.749355, 26.0);
           System.out.println("OBJECT_LOC: " + OBJECT_LOC);

           float distance = BASE_LOC.distance(OBJECT_LOC);
           float az = BASE_LOC.azimuth(OBJECT_LOC);

           LatLonPoint CONVERTED_POINT = BASE_LOC.getPoint(distance, az);

           System.out.println("CONVERTED_POINT " + CONVERTED_POINT);

   }

}

Some information is available here - http://www.movable-type.co.uk/scripts/latlong.html

七色彩虹 2024-12-16 00:01:39

无论如何,当您执行 BASE_LOC.distance() 调用时,您将在两个距离的参数中的 OBJECT_LOC/BASE_LOC 之间进行交换。其中一个为 OBJECT_LOC/BASE_LOC,另一个为 BASE_LOC/OBJECT_LOC。

For what it's worth, when you're doing your BASE_LOC.distance() calls, you're swapping between OBJECT_LOC/BASE_LOC in the arguments for the two distances. OBJECT_LOC/BASE_LOC in one, BASE_LOC/OBJECT_LOC in the other.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文