(地理)位置的通用数据结构/格式是什么?如何比较它们?
通用(或独立于设备)物理位置的结构是什么?我的猜测是它可能是一个具有两个长字段的结构,或者类似的东西。
另外,给定一个目的地位置和两个候选位置,是否有一种简单的算法来确定哪个候选位置最接近目的地?我并不是真的在寻找一个可以处理所有这些的库或服务,尽管这可能是一个选项(在 Java 中),而是我想要一些非常简单的低级概念,我可以自己实际操作它们。
谢谢!
编辑 鉴于 f1sh 指出的计算的复杂性 - 是否有一个不错的小型 Java 库可以处理半正弦计算?
What is the structure of a generic (or device independent) physical location? My guess is it might be a struct with two long fields, or something similar.
Also, given one destination location, and two candidate locations, is there a simple algorithm for determining which candidate is closest to the destination? I'm not really looking for a library or service that handles all of this, though that could be an option (in Java), rather I want some very simple low level concepts that I can actually manipulate myself.
Thanks!
Edit
Given the intricasies of the calculations noted by f1sh - is there a nice small Java library that handles haversine calculations?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
正如您和 Andreas_D 已经提到的那样(2 个双字段),在类中存储纬度和经度对任何人来说都不应该成为问题。
棘手的部分是,计算该行星表面上 2 个点之间的距离并不像 2 个 2D 点之间的常见距离公式那么简单。
必须考虑以下事实:
Storing latitude and longitude in a class should't be a problem to anybody, as you and Andreas_D already mentioned (2 double fields).
The tricky part is that calculating the distance between 2 Points on the surface of this planet is not as simple as the common distance formula between 2 2D-Points.
The following facts have to be considered:
GPS 设备通常提供以下有关位置的数据:
(更不用说速度、目的地、卫星等)
现在问题的第二部分:您可以使用半正矢公式来计算所有候选人之间的距离您的位置,然后按此距离对它们进行排序。不确定是否有更通用/科学的方法。
编辑:看看半正矢公式
GPS devices are commonly provides following data about location:
(not to speak about speed, destination, satellites, etc.)
Now second part of your question: you can use haversine formula to calculate distance between all candidates and your location, and then sort them by this distance. Not sure about some more generic / scientific approach.
EDIT: Take a look at haversine formula here. Code example is also there. I don't think that you need some library for this.
是的,像这样的类
足以存储地理位置。您可能需要添加 setter 方法来确保 lat、lon 始终在有效范围内,否则 Geo 对象可能具有无效状态。
Yes, a class like
is sufficient to store a geographical location. You might want to add setter method to make sure, that lat, lon are always in a valid range, otherwise a Geo object might have an invalid state.
这显然是最准确的公式,半正弦在短直径上不准确:
参考
This is apparently the most accurate formula, the haversine being inaccurate over short diatances:
Reference